View Full Version : Need Help with PHP Script
jardanc@yahoo.com
09-29-2010, 03:17 AM
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 :D but I really need to be able to see what people are saying for this to work
|HF|Binarian
10-03-2010, 09:20 PM
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
jardanc@yahoo.com
10-04-2010, 01:44 AM
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 :|
|HF|Binarian
10-04-2010, 02:50 AM
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
|HF|Binarian
10-04-2010, 03:57 AM
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
jardanc@yahoo.com
10-04-2010, 03:17 PM
I Like it :D
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?:confused:
|HF|Binarian
10-04-2010, 07:51 PM
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
phong
10-06-2010, 09:46 PM
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,"type":"chat"
jardanc@yahoo.com
10-08-2010, 06:23 PM
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
|HF|Binarian
10-08-2010, 08:08 PM
Perhaps I am misunderstanding you. Run it by me again....what exactly are you trying to get to register nicknames?
|HF| bin
Gh0stalk3r
10-11-2010, 04:39 PM
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.:D
phong
10-11-2010, 05:31 PM
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,"type":"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.
Gh0stalk3r
10-11-2010, 06:38 PM
...
ok, this will be fun :)
|HF|Binarian
10-11-2010, 07:05 PM
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
Gh0stalk3r
10-11-2010, 09:57 PM
:(
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?
|HF|Binarian
10-11-2010, 10:11 PM
I sent you an email containing my palp.php file. Below is a description of what specifically you need to know.
// 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
I use that. I created the file beforehand, but I dont think that was necessary.
Located in the middle of parse_chat(), I put:
write_chat("$obj->port: " . addslashes($row['p_nickname']) . ": $obj->message\n");
This outputs the following into the file /home/USER/altitude/servers/chatlog.txt:
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...
Gh0stalk3r
10-11-2010, 10:29 PM
that is cool :D
I think with the admin thingy you put in there, that I can put in my legendary shutdown command :D
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.
Gh0stalk3r
10-11-2010, 10:36 PM
???
what the... IT CALLED MEH ALICE!!!
It wrote my name as Alice and I haven't the faintest clue why :|
Gh0stalk3r
10-11-2010, 10:47 PM
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?
|HF|Binarian
10-11-2010, 11:02 PM
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
Gh0stalk3r
10-11-2010, 11:41 PM
write_chat("$obj->port: " . addslashes($row['p_nickname']) . ": $obj->message\n");
echo ("Chat:" . addslashes($row['p_nickname']) . ": $obj->message\n");
right after your code, will write chats to the palp console instead of the p_id
|HF|Binarian
10-12-2010, 02:23 AM
good luck!
Gh0stalk3r
10-12-2010, 03:25 PM
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 >:D
I have some plans for it, and I think I can implement the log into a window on my app:D
|HF|Binarian
10-12-2010, 03:59 PM
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
Gh0stalk3r
10-12-2010, 06:09 PM
lol...:p
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 :D
It works great so far
vBulletin® v3.8.2, Copyright ©2000-2013, Jelsoft Enterprises Ltd.