Altitude Game: Forums  

Go Back   Altitude Game: Forums > Altitude Support > Dedicated Server
FAQ Community Calendar

Dedicated Server Discuss technical issues related to hosting your own servers.

Reply
 
Thread Tools Display Modes
  #1  
Old 09-29-2010, 04:17 AM
jardanc@yahoo.com jardanc@yahoo.com is offline
Banned
 
Join Date: Jul 2009
Posts: 45
Send a message via Yahoo to jardanc@yahoo.com
Default 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
Reply With Quote
  #2  
Old 10-03-2010, 10:20 PM
|HF|Binarian |HF|Binarian is offline
Senior Member
 
Join Date: Oct 2010
Location: RIT
Posts: 122
Default 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
Reply With Quote
  #3  
Old 10-04-2010, 02:44 AM
jardanc@yahoo.com jardanc@yahoo.com is offline
Banned
 
Join Date: Jul 2009
Posts: 45
Send a message via Yahoo to jardanc@yahoo.com
Default

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 :|
Reply With Quote
  #4  
Old 10-04-2010, 03:50 AM
|HF|Binarian |HF|Binarian is offline
Senior Member
 
Join Date: Oct 2010
Location: RIT
Posts: 122
Default 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
Reply With Quote
  #5  
Old 10-04-2010, 04:57 AM
|HF|Binarian |HF|Binarian is offline
Senior Member
 
Join Date: Oct 2010
Location: RIT
Posts: 122
Default

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
Reply With Quote
  #6  
Old 10-04-2010, 04:17 PM
jardanc@yahoo.com jardanc@yahoo.com is offline
Banned
 
Join Date: Jul 2009
Posts: 45
Send a message via Yahoo to jardanc@yahoo.com
Default

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?
Reply With Quote
  #7  
Old 10-04-2010, 08:51 PM
|HF|Binarian |HF|Binarian is offline
Senior Member
 
Join Date: Oct 2010
Location: RIT
Posts: 122
Default 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
Reply With Quote
  #8  
Old 10-06-2010, 10:46 PM
phong phong is offline
Senior Member
 
Join Date: Jul 2009
Location: Chicago
Posts: 372
Default

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.
Reply With Quote
  #9  
Old 10-08-2010, 07:23 PM
jardanc@yahoo.com jardanc@yahoo.com is offline
Banned
 
Join Date: Jul 2009
Posts: 45
Send a message via Yahoo to jardanc@yahoo.com
Default

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
Reply With Quote
  #10  
Old 10-08-2010, 09:08 PM
|HF|Binarian |HF|Binarian is offline
Senior Member
 
Join Date: Oct 2010
Location: RIT
Posts: 122
Default hmm

Perhaps I am misunderstanding you. Run it by me again....what exactly are you trying to get to register nicknames?

|HF| bin
Reply With Quote
  #11  
Old 10-11-2010, 05:39 PM
Gh0stalk3r Gh0stalk3r is offline
Member
 
Join Date: Oct 2010
Location: Mars
Posts: 39
Default

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.
Reply With Quote
  #12  
Old 10-11-2010, 06:31 PM
phong phong is offline
Senior Member
 
Join Date: Jul 2009
Location: Chicago
Posts: 372
Default

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.
Reply With Quote
  #13  
Old 10-11-2010, 07:38 PM
Gh0stalk3r Gh0stalk3r is offline
Member
 
Join Date: Oct 2010
Location: Mars
Posts: 39
Default

...


ok, this will be fun
Reply With Quote
  #14  
Old 10-11-2010, 08:05 PM
|HF|Binarian |HF|Binarian is offline
Senior Member
 
Join Date: Oct 2010
Location: RIT
Posts: 122
Default

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
Reply With Quote
  #15  
Old 10-11-2010, 10:57 PM
Gh0stalk3r Gh0stalk3r is offline
Member
 
Join Date: Oct 2010
Location: Mars
Posts: 39
Default



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?
Reply With Quote
  #16  
Old 10-11-2010, 11:11 PM
|HF|Binarian |HF|Binarian is offline
Senior Member
 
Join Date: Oct 2010
Location: RIT
Posts: 122
Default

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
I use that. I created the file beforehand, but I dont think that was necessary.

Located in the middle of parse_chat(), I put:


Code:
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...
Reply With Quote
  #17  
Old 10-11-2010, 11:29 PM
Gh0stalk3r Gh0stalk3r is offline
Member
 
Join Date: Oct 2010
Location: Mars
Posts: 39
Default

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.
Reply With Quote
  #18  
Old 10-11-2010, 11:36 PM
Gh0stalk3r Gh0stalk3r is offline
Member
 
Join Date: Oct 2010
Location: Mars
Posts: 39
Default

???


what the... IT CALLED MEH ALICE!!!



It wrote my name as Alice and I haven't the faintest clue why :|
Reply With Quote
  #19  
Old 10-11-2010, 11:47 PM
Gh0stalk3r Gh0stalk3r is offline
Member
 
Join Date: Oct 2010
Location: Mars
Posts: 39
Default

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?
Reply With Quote
  #20  
Old 10-12-2010, 12:02 AM
|HF|Binarian |HF|Binarian is offline
Senior Member
 
Join Date: Oct 2010
Location: RIT
Posts: 122
Default

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
Reply With Quote
  #21  
Old 10-12-2010, 12:41 AM
Gh0stalk3r Gh0stalk3r is offline
Member
 
Join Date: Oct 2010
Location: Mars
Posts: 39
Default

PHP Code:
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
Reply With Quote
  #22  
Old 10-12-2010, 03:23 AM
|HF|Binarian |HF|Binarian is offline
Senior Member
 
Join Date: Oct 2010
Location: RIT
Posts: 122
Default

good luck!
Reply With Quote
  #23  
Old 10-12-2010, 04:25 PM
Gh0stalk3r Gh0stalk3r is offline
Member
 
Join Date: Oct 2010
Location: Mars
Posts: 39
Default

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
Reply With Quote
  #24  
Old 10-12-2010, 04:59 PM
|HF|Binarian |HF|Binarian is offline
Senior Member
 
Join Date: Oct 2010
Location: RIT
Posts: 122
Default

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
Reply With Quote
  #25  
Old 10-12-2010, 07:09 PM
Gh0stalk3r Gh0stalk3r is offline
Member
 
Join Date: Oct 2010
Location: Mars
Posts: 39
Default

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
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:11 AM.


Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.
2008 Nimbly Games LLC