68 posts
Posted 04 January 2013 - 12:03 PM
One of the functionalities I need on my multiplayer server is that computers need to know the minecraft username of the player operating them (i.e the person that right clicked the computer to run its program). This is obviously not a standard Lua function, and from what I've been reading, this is not amongst the functionalities of the standard CC APIs.
Now, since such information is obviously not accessible by Lua itself, I figure I would have to write a custom API in a different language to retrieve this information, but I am not entirely sure of how to do this.
I've been reading around and found instructions on where to place custom APIs if I want them to be default, but I am not entirely sure where would I put them if I wanted them available but not loaded by default; and I don't recall having found any information on how to write APIs on external languages.
I am pretty new to this, so if these are common problems (I searched the forums but didn't find what I needed exactly) I'd appreciate if someone knowledged enough could nudge me in the right direction.
Thanks in advance for your attention.
8543 posts
Posted 04 January 2013 - 01:49 PM
I'm going to nudge this in the right direction by moving the question to the peripheral help section. You'd need a peripheral to do this.
1054 posts
Posted 04 January 2013 - 02:20 PM
It's quite easy to make this (I've done something similar in an experiment once). But unfortunately I got no time for this myself (exams), I hope someone else does. The main issue here is that you can't define one person as using the computer because you can be on a computer with multiple persons at once. You could in theory queue an event when someone opens a computer though. This brings some issues with it as well, as I believe that you have no option for doing that with the CC API. Thus - 2 options I can think of now - you'd need reflection (it's a rather slow technique, but you wouldn't open computers at a high rate normally), or you'd use some forge hooks to do this (this is how I did it). I also didn't use a peripheral back then, but rather injected a custom API with a Java backend into the computer, also using forge hooks (and inheritance). I've been told that dan200 isn't a big fan of poking into the inner workings of CC though (and redistributing the code doing so especially).
68 posts
Posted 04 January 2013 - 04:23 PM
I'm not sure what you mean by forge hooks. I've never done reflection before, so I don't know how "slow" it would be, but I wouldn't mind since even if computers are not started very often, the code that needs this would only be ran on a handful of specific computers.
I'm interested in knowing in a bit more detail how you pulled this off. Coding a custom peripheral sounds a bit far fetched to me as I have never written anything for Minecraft, so custom blocks are a bit far for me at the moment.
1054 posts
Posted 04 January 2013 - 04:30 PM
I'm sorry for not being clear, but everything I said was related to a Java based solution (thus a minecraft mod). I was continuing on what Lyqyd said. It doesn't need to be a block though, but I don't think that's your main problem. :P/> so, forge hooks are functions placed in the minecraft code by the forge mod. These functions are then being called on certain actions, that way you can for example do something on right clicking a block. (Just wanted to fill you in on that)
68 posts
Posted 04 January 2013 - 05:35 PM
That sounds interesting and possible, but I'll have to research how to do that. I figure I can also take the option I first though of, which is just asking the user who they are, but there are other problems with that.
Also, did you say multiple users can be using a computer at the same time? How does that work? Does each one see a different instance of the console, or it's as if everyone were looking at the same screen and mashing on the same keyboard?
2217 posts
Location
3232235883
Posted 04 January 2013 - 08:11 PM
if any player presses a key (including mouse buttons) it will pull that event
yea, its more like the same people smashing the keyboard :P/>
its also the reason why we dont get key_up and key_down events
:s
871 posts
Posted 05 January 2013 - 04:33 AM
At the risk of shameless self-promotion, if you only need this in a few specific instances on a few computers running, I assume, special programs, you might save yourself some trouble and just use
my BioLock peripheral. With a minor change to it's .cfg file and it sends the username of the player who clicks on it instead of pseudorandom "fingerprints." Your program could wait for a player to click the biolock then activate for that user. Note that the computer, once so activated, could be used by anyone until locked again. You could minimize this problem by having the computer "timeout," relocking if nobody is there is no user input for some time. If that's an unacceptable problem, then I guess you'll just have to figure out how to notify the computer whenever anyone enters or exits the gui, as lyqyd and orwell have been explaining.
On a tangent, I miss getting key==1 events when the player hit escape, it provided an easy way to automatically lock computers when a user closed the gui…
68 posts
Posted 06 January 2013 - 04:03 PM
That, actually, looks like an excellent way to do what I need to do. Thanks a lot, GopherAtl. I probably will be using your peripheral for this.
Now the only problem I'd have with this is that all computers seem to turn off when the chunks are unloaded and reloaded later, at least in the version I have, and sadly there doesn't seem to be a way to reboot them automatically. This is supposed to be a sort of unattended quest system, the point is to not have a mod/admin around :/
2447 posts
Posted 07 January 2013 - 07:14 AM
They shouldn't do - what version of CC you using?
68 posts
Posted 07 January 2013 - 07:48 AM
Ah, well observed. I'm using the 1.33 version packed in Tekkit for local tests. Boy, it just dawned on me it runs on Minecraft 1.2.5! My bad. If this is fixed in newer versions, I guess I shouldn't worry.
2217 posts
Location
3232235883
Posted 07 January 2013 - 07:49 AM
yea, its implemented in the newer versions
871 posts
Posted 07 January 2013 - 09:38 AM
ah, yeah, you'd need at LEAST 1.3.2 to use my BioLock peripheral, just for the record. 1.2.5 is not supported.
68 posts
Posted 07 January 2013 - 12:41 PM
Yeah I'll start using 1.4.6/7 shortly. This was just preliminary testing, the server won't even have Tekkit or whatever, it'll have the latest version of CC directly.
1054 posts
Posted 07 January 2013 - 01:13 PM
Yeah I'll start using 1.4.6/7 shortly. This was just preliminary testing, the server won't even have Tekkit or whatever, it'll have the latest version of CC directly.
You could also consider OCS. I'm not sure if GopherAtl's peripheral gives you a username. Open CC Sensors does give the playername, but not if he's on the computer. You could 'guess' that he's on the computer by using the relative coords of the player.
68 posts
Posted 07 January 2013 - 03:27 PM
It seems it can be configured to return a username, so that's probably what I need. Even if it didn't and it only returned a unique string seeded by the username, it would still be useful (but require a few extra steps to set up on my end). If it doesn't work out I'll give that a try too, though!