Assistance coding ladder for wesnothd

Discussion of all aspects of multiplayer development: unit balancing, map development, server development, and so forth.

Moderator: Forum Moderators

Post Reply
mcnigelmcgruff
Posts: 15
Joined: December 23rd, 2010, 6:53 pm

Assistance coding ladder for wesnothd

Post by mcnigelmcgruff »

Hello,
I am attempting to create something that has been requested by a friend of mine: a built-in ladder system in wesnothd.
I have made some progress, but have hit a wall with some issues.
So far, I have managed to copy the db_query function and required includes from forum_user_handler.cpp/.hpp to appropriate spots in game.cpp/.hpp. It is still very rough (the variables for connecting to the database are all hard-coded, it initiates a connection every time it needs to access something from the database, etc.), all things that I can work out later. I have gotten it to read an incremental number from the database and assign it as a global variable (a game id), then write to the database the starting time/date of each game with the game id when game_start() is initiated, then write the ending time/date when the instance of "game" is destroyed.
The problem I am having is with usernames. I wanted to get a list of usernames at the beginning of each game to write to the database, but can't get anything to work.
Right now this is what I have:

Code: Select all

conn = mysql_init(NULL);

if(!conn || !mysql_real_connect(conn, ********,  *********, *******, ********, 0, NULL, 0)) {
	ERR_UH << "Could not connect to database: " << mysql_errno(conn) << ": " << mysql_error(conn) << std::endl;
}
std::stringstream player1;
player1 << list_users(players_, __func__);
db_query("insert into wesnoth.testing3 values ("+player1.str()+")");
(Connection info starred out for security reasons.)

Everything compiles and runs without error, but nothing get recorded in that particular table, while other queries just below it work fine.
I copied "list_users(players_, __func__)" from earlier in the function, where it is writing to LOG_GAME.
Just not sure why I'm not getting anything...

Another problem I've run into is where to put the code to record player's deaths. I just need someone to point me to where wesnothd makes the decision that a player is dead so that it can turn them into an observer or kick them from the game. Once I find the right spot where it makes this decision, I can go from there.

Note: I have SOME experience in C/C++, but not a lot (I do more work with PHP). I know this code looks terrible and is probably not the right way to do it. For now, all I am worried about it getting it to work, I can change efficiency later.

Any help that can be given will be appreciated.
Thank you.
Kernigh
Posts: 107
Joined: February 13th, 2007, 10:21 pm
Location: United States
Contact:

Re: Assistance coding ladder for wesnothd

Post by Kernigh »

mcnigelmcgruff wrote:

Code: Select all

db_query("insert into wesnoth.testing3 values ("+player1.str()+")");
What is value of string "insert into wesnoth.testing3 values ("+player1.str()+")"? I suspect that your string is not a valid database query. I am not sure (because I know not SQL), but you might be missing quotes around the names of the players. This might be SQL problem, and you might need help from someone who knows SQL.
mcnigelmcgruff
Posts: 15
Joined: December 23rd, 2010, 6:53 pm

Re: Assistance coding ladder for wesnothd

Post by mcnigelmcgruff »

Thank you! That worked exactly. I don't know how I could be so stupid. I just get a little nervous coding C++, but even then that was a basic mistake. It writes the usernames to the database correctly after putting single quotes around the string.
Now all I need help with is finding where wesnothd makes the decision that a player is dead.

Thanks
mcnigelmcgruff
Posts: 15
Joined: December 23rd, 2010, 6:53 pm

Re: Assistance coding ladder for wesnothd

Post by mcnigelmcgruff »

Still looking for some help with the location of the code that decides a player is dead.
Maybe someone from the development team could point me in the right direction?

Thanks
Max
Posts: 1449
Joined: April 13th, 2008, 12:41 am

Re: Assistance coding ladder for wesnothd

Post by Max »

Post Reply