|
Dedicated Server Discuss technical issues related to hosting your own servers. |
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Need Help with PHP Script
Ok, if anyone out there knows I need help with a php script. I'm trying to find a way to log "chat" from players to the main log. Does anyone know how to do that? Don't ask why I need it, it's for a suprise but I really need to be able to see what people are saying for this to work
|
#2
|
|||
|
|||
try this...
http://altitudegame.com/forums/showthread.php?t=2708
The above link will help you initiate a php patch into the altitude game. It outputs its own log which included chat messages. It should not be difficult at all to add a few lines of code (in palp.php, i think, under parseChat() or something like that) to either redirect or additionally include a text append to a different file. R |
#3
|
|||
|
|||
I looked at it, but doesn't palp require a sql server? And it also doesn't display the name of the player, but a number, ex. "player 1" I'm Building a server administration app and I need a chat monitoring something that works like the C-Slaps version, but I have no clue how to import that to Mac OSX :|
|
#4
|
|||
|
|||
hmmm
I will think on it and look at what i have set up myself. ATM i must do laundry, but i will look in on it.
|HF| bin |
#5
|
|||
|
|||
ok so first off yes, it requires mysql, which as far as I understand is a purely local "server" that "hosts" sql databases. aka it takes up a miniscule amount of server resources.
Secondly, conveniently, Darwin (the OSX kernel) is very similar to the standard Unix shell (i am using bash on debian to host my servers). Also, I am using a mac to type this so I think I can try to make things work. A disclaimer: what I am about explain uses PHP. i do not understand a bit of PHP. However, I do know C++ and Java, so I understand the basic structure of PHP. OK! on the real stuff. The following function in palp.php will look at every chat message typed by any user: function parse_chat($obj) { # Debug output if ($GLOBALS['debug']) { echo "PALP: Parsing " .$obj->port. " chat from " .$obj->player. " -- " .$obj->message. " \n"; } if (!$obj->server) { ...........etc. Specifically, look at the lines: if ($obj->message == "!help") { send_command("$obj->port,console,serverWhisper \"" . addslashes($row['p_nickname']) . "\" Available commands: !restricted, !session, !tournament"); } If any user types "!help" it will be displayed in altitude as a regular chat message (albeit a strange one) but will also execute the send_command() function. Which is as follows: function send_command($command) { echo "Sending command " .$command. "\n"; $cf = fopen($GLOBALS['commandfile'], "a"); fwrite($cf, "$command\n"); fclose($cf); } The $GLOBALS['commandfile'] is equivalent to the command.txt file found in your ~/altitude/servers directory...or wherever you have the Altitude Server installed This particular function prints to the shell, then essentially appends (not writes, appends, there is a difference) the command sequence assembled in the parse_chat() if statement above is written to the command.txt file. This is where what you need comes in (sorry to take so long to get there). If you create a new method, you should be able print everything that is sent in a chat into a file. For example, add the following to palp.php after send_command(): function printchat($message) { $cf2 = fopen("thepathto/yournewfile", "a"); fwrite($cf2, "$message\n"); fclose($cf2); } Then, back at the parse_chat() function, add the following on the blank line immediately after the "// Process here" comment: printchat("\"" . addslashes($row['p_nickname']) . "\": $obj->message\n") I *believe* that this will print every single chat message including team messages to an external file. NOTE: said external file MUST already exist before this is run. If it does not, Im sure all sort of nasty errors will happen. Read that thru a time or three and then tell me what you think. |HF| bin |
#6
|
|||
|
|||
I Like it
Thx. Binarian. Now I can get some real work down with this applications. I've been working first with applescript to work a server chat system and a remote commandline, but that is much as I have for now. This is really good. I wonder though if this script still shows players number instead of name? |
#7
|
|||
|
|||
observe
printchat("\"" . addslashes($row['p_nickname']) . "\": $obj->message\n")
That line (which was included in the above explaination) will display the player name instead of number. |HF| bin |
#8
|
|||
|
|||
sql is only used for stat tracking, essentially you could just cut out all the statistical functions and turn it strictly into a logger/chat parser.
Actually nevermind.. I forgot altitude only outputs the userid and serverid of the chat message to the json log, not the nickname. Palp keeps track of userids and associated nicknames upon joining the server (in sql), so it was able to output their nickname in it's log to make it easier to read. Unless lamster adds nicknames to the logs there really is no easy way to do it. "port":50101,"message":"try turbo","time":3237617,"player":7,"server":false,"t ype":"chat" Last edited by phong; 10-06-2010 at 11:03 PM. |
#9
|
|||
|
|||
I think phong is right, I tried the script Binarian, and I couldn't get it to work .
I couldn't get it to register nicknames |
#10
|
|||
|
|||
hmm
Perhaps I am misunderstanding you. Run it by me again....what exactly are you trying to get to register nicknames?
|HF| bin |
#11
|
|||
|
|||
Dont worry it's me jardanc@yahoo.com
I didn;t like the idea of registering my username accross the board throug my name :P still, I'm trying to make a standalone app, mabye using Palp like phongs, but with guis on a mac platform. I have an interface laid out, but I'm struggling on trying to get the logs to register chat without a player number, but name instead, that way it would be easier to recognize who a person is in a server. |
#12
|
|||
|
|||
As I mentioned before, the only way to currently determine what player id is associated with a nickname is to log the data when the player joins the server (and remove it when they leave).
For example this join message: {"port":50011,"time":342329580,"level":60,"player" :2,"nickname":"[fLb]Kuja900","aceRank":0,"vaporId":"57ed0849-4a29-4b8b-9cb3-c904e3dd49ae","type":"clientAdd","ip":"99.178.173. 62:27272"} You know kuja is player id 2 on server/port 50011. Unfortunately, future messages will only display this ID: {"port":50011,"message":"peace man","time":342693418,"player":2,"server":false,"t ype":"chat"} So there are 3 options: 1) Have something running all the time to monitor player id's->nicknames and store it in a database (palp already does this). So either make something or make palp a requirement and build off that. 2) Have your chat app just show player id's for those who were already on the server prior to launching the chat app. Anyone who joins while the app is running you could pull the nickname from. You'd have to monitor pings to know how many players are currently on the server. 3) Ask/beg lamster to add nicknames to json/message logs. This can also only be done server side unless you built a full on chat client using altitude's protocol. Last edited by phong; 10-11-2010 at 06:50 PM. |
#13
|
|||
|
|||
...
ok, this will be fun |
#14
|
|||
|
|||
Yea I just use palp. I already made a mini chatlog that just dumps ALL chat messages into a txt file in the form of PORT: NAME: MESSAGE.
Clearly, I recommend palp, since it is easy to adapt and already has the database set up by the time you get it to run. |HF| bin |
#15
|
|||
|
|||
this is not fun, its depressing. I think I've tried everything, but I think I may just not be getting it :\ I changed some fields to register p_nickname = '" . $obj->nickname. "' or something, but I can't get it to work... Binarian, how'd you get it to work to write to a separate file? I need something like that right now... I'm thinking echo (text here) --> /file.txt right? |
#16
|
|||
|
|||
I sent you an email containing my palp.php file. Below is a description of what specifically you need to know.
Code:
// Start write_chat function function write_chat($command) { $cf2 = fopen("/home/USER/altitude/servers/chatlog.txt", "a"); fwrite($cf2, "$command"); fclose($cf2); } // End write_chat function Located in the middle of parse_chat(), I put: Code:
write_chat("$obj->port: " . addslashes($row['p_nickname']) . ": $obj->message\n"); 27276: |HF|binarian: im guessing youre on autojoin? 27276: TinyBear: yeah' 27276: |HF|binarian: lol 27276: |HF|binarian: !session 27276: |HF|binarian: !restart 27276: |HF|binarian: i like this map 27276: TinyBear: never played it befor 27276: |HF|binarian: !restart 27276: Easy Bot 7: !help 27279: Pretoriano: hi coward aka SERVERPORT: USERNAME: MESSAGE Is this what you are looking for? BTW the palp file includes my !restart implementation... |
#17
|
|||
|
|||
that is cool
I think with the admin thingy you put in there, that I can put in my legendary shutdown command Anyways, thanks for the palp file, I think I can rewrite the write-to-log function to write and do echo into the terminal to show it there. |
#18
|
|||
|
|||
???
what the... IT CALLED MEH ALICE!!! It wrote my name as Alice and I haven't the faintest clue why :| |
#19
|
|||
|
|||
this is creepy... Anyways, I came accross some fields in my database which is apparently keeping track of people and not clearing itself out :\ and My name was set to Alice because someone named Alice came on with a player id of 0m and Bot 2 had a player id of 1, which is why another person came on with that name, um Binarian, do you know how to fix this?
|
#20
|
|||
|
|||
Shut down your server, shut down php, start php, then restart your server. do it in that order. if the problem is still there, then log into mysql and delete the altitude database, then recreate it, then shut down the server and php script, then do:
--mysql -u xxxx -pPassword databasename < palp.sql to reinitialize the database. Then start the php script, then start your server |HF| bin |
#21
|
|||
|
|||
PHP Code:
|
#22
|
|||
|
|||
good luck!
|
#23
|
|||
|
|||
The Admin idea in the script was a good idea. For example, if I wanted to do a fast kick, I could do: !k Gh0stalk3r
or !b Gh0stalk3r to banish forever > I have some plans for it, and I think I can implement the log into a window on my app |
#24
|
|||
|
|||
I KNEW i should have copyrighted the admin part :P
No seriously, just remember to actually change the vaporIDs to what they should be (in the isAdmin() function). Also, if you want to have a "you cant do that cause you aint admin" message, you need to do that outside of isAdmin(). Unless you change it. which you should, because I just threw together the code without thinking about it in depth. |HF| bin |
#25
|
|||
|
|||
lol...
I have the vaporid's set and the message... I like it the way it is right now, sounds like how a server should sound, HOWEVER, executing the !restart command, I got a php notice about echoing the vaporid of who said it, so i just removed that and it worked, had a friend come on and try it and he couldnt do it It works great so far |
|
|