PDA

View Full Version : CoD4 - MySQL problem



BlancO
19th September 2013, 21:09
I've got a problem with MySQL. I don't know what's wrong. After this MySQL is still the same. There's no players table.

.gsc script


mysql = std\mysql::mysql_real_connect(std\mysql::mysql_ini t(), level.mysqlAdress, level.mysqlUser, level.mysqlPass, level.mysqlDb, level.mysqlPort)

std\mysql::mysql_query(mysql, "CREATE TABLE players (id int NOT NULL AUTO_INCREMENT, name varchar(30), score varchar(12), kills varchar(9), PRIMARY KEY(id))");
std\mysql::mysql_close(mysql);


.sh script


cd /home/cod4/zombie
LD_LIBRARY_PATH="/home/libcod/mysql" LD_PRELOAD="/home/libcod/libcod4_1_7.so" ./cod4x17a_lnxded +set dedicated "2" +set net_port "28961" +set fs_basepath "/home/cod4/zombie/" +set fs_game "mods/nlMod" +exec nlMod.cfg +map_rotate


Contents of /home/libcod:


root@blanco:/home/libcod# ls
libastar.so libcod2_1_2.so libcod2.so mysql
libcod1_1_5.so libcod2_1_3.so libcod4_1_7.so


Contents of /home/libcod/mysql:


root@blanco:/home/libcod/mysql# ls
libmysqlclient.a libmysqlclient.so libmysql.so.16
libmysqlclient_r.so libmysql.so libmysql.so.16.0.0

kung foo man
19th September 2013, 21:31
It might be everything, best is to check always for errors and printing them:



#include std\mysql;

mysql_test()
{
host = getcvar("mysql_host");
user = getcvar("mysql_user");
pass = getcvar("mysql_pass");
db = getcvar("mysql_db");
port = getcvarint("mysql_port");


mysql = mysql_init();

if ( ! isDefined(mysql))
{
std\io::println("mysql not defined!");
return;
}

std\io::print("mysql=" + ("2"+2) + "\n");

ret = mysql_real_connect(mysql, host, user, pass, db, port);
if (!ret)
{
std\io::print("errno="+mysql_errno(mysql) + " error=''"+mysql_error(mysql) + "''\n");
mysql_close(mysql);
return 0;
}

std\io::print("affected_rows="+mysql_affected_rows(mysql)+"\n");



name = "fo\"0'z0`r"; // all user-input is evil!
name = mysql_real_escape_string(mysql, name); // so escape it :)

theQuery = "SELECT * FROM players";
theQuery = "SELECT \""+name+"\" as first,2 as second,3 as third UNION SELECT 11,22,33";

std\io::print(theQuery);

ret = mysql_query(mysql, theQuery);
if (ret != 0)
{
std\io::print("errno="+mysql_errno(mysql) + " error=''"+mysql_error(mysql) + "''\n");
mysql_close(mysql);
return 0;
}

result = mysql_store_result(mysql);

std\io::print("num_rows="+mysql_num_rows(result) + " num_fields="+mysql_num_fields(result)+"\n");

mysql_field_seek(result, 0);
while (1)
{
result_name = mysql_fetch_field(result);
if (!isString(result_name))
break;
std\io::print("field-name=" + result_name+"\n");
}

while (1)
{
row = mysql_fetch_row(result);
if (!isDefined(row))
{
//std\io::print("row == undefined\n");
break;
}
output = "";
for (i=0; i<row.size; i++)
output += row[i] + " ";
std\io::print(output+"\n");
}

mysql_free_result(result);

mysql_close(mysql);

}


Example from: http://killtube.org/downloads/cod2/exampleserver/main/std/mysql_debugging.gsc

Sense
19th September 2013, 21:34
Do you have a mysql database? if not then here we go.

Before installing Mysql, make sure your repositories are up to date:

apt-get update

Now you need Apache:

apt-get install apache2

To install Mysql, enter terminal or screen and type in these commands:

apt-get install mysql-server

Follow the instructions.
If you miss the chance to set the password then you can always do it within the mysql shell.

Run the mysql setup script:

mysql_secure_installation

The prompt will ask you for your current root password. Type it in.

Once again follow the instructions and remember pressing N is for No and Y for yes.

INSTALLING PHP? not sure if it's necessary but here we go:

apt-get install php5 php-pear php5-suhosin php5-mysql

Answer YES twice and it will install itself.

Finish up by restarting apache:

service apache2 restart

YuriJurek
19th September 2013, 21:36
Well all of that is already installed no worry about such a basic stuff

Sense
19th September 2013, 21:50
Well all of that is already installed no worry about such a basic stuff
Just tried to help, show a little gratitude instead..

BlancO
19th September 2013, 22:10
I think it's something wrong with libcod. I even don't receive any of these "std\io::print". I have mysql-server, apache2, php5 installed.

kung foo man
19th September 2013, 22:21
When you start the server, you should see something like this:



> [WARNING] Compiled for: 210
Compiled: Sep 17 2013 23:08:19
> [INFO] value of closer=08111d32
> [PLUGIN LOADED]
CoD2 MP 1.0 build linux-i386 Oct 24 2005
----- FS_Startup -----
Current search path:
/home/k_deathrun/zombots
/home/k_deathrun/main/iw_14.iwd (4038 files)
/home/k_deathrun/main/iw_13.iwd (22624 files)
/home/k_deathrun/main/iw_12.iwd (1016 files)
/home/k_deathrun/main/iw_11.iwd (1462 files)
/home/k_deathrun/main/iw_10.iwd (1936 files)
/home/k_deathrun/main/iw_09.iwd (2142 files)
/home/k_deathrun/main/iw_08.iwd (2723 files)
/home/k_deathrun/main/iw_07.iwd (3384 files)
/home/k_deathrun/main/iw_06.iwd (990 files)
/home/k_deathrun/main/iw_05.iwd (928 files)
/home/k_deathrun/main/iw_04.iwd (698 files)
/home/k_deathrun/main/iw_03.iwd (26 files)
/home/k_deathrun/main/iw_02.iwd (40 files)
/home/k_deathrun/main/iw_01.iwd (16 files)
/home/k_deathrun/main/iw_00.iwd (102 files)
/home/k_deathrun/main
/home/k_deathrun/raw
/home/k_deathrun/raw_shared
/home/k_deathrun/devraw
/home/k_deathrun/devraw_shared




Do you see the [PLUGIN LOADED]? It might can't find the mysql-dependency

YuriJurek
19th September 2013, 23:08
Just tried to help, show a little gratitude instead..
I mean no disrespect maybe it just sounds so a little bit.

BlancO
22nd September 2013, 21:27
I can't see "[PLUGIN LOADED]"...

.sh file


export LD_LIBRARY_PATH="/home/cod4/server/libs:/home/cod4/server/libs/mysql"
export LD_PRELOAD="/home/cod4/server/libs/libcod4_1_7.so"

cd /home/cod4/server
./cod4_lnxded +set dedicated "2" +set net_port "28961" +set fs_basepath "/home/cod4/server" +set fs_homepath "/home/cod4/server" +set fs_game "mods/nl_zom" +exec zom.cfg +map_rotate

kung foo man
22nd September 2013, 21:58
cod4_lnxded is a start-script, call cod4_lnxded_bin directly

BlancO
22nd September 2013, 23:43
Set it to:



export LD_LIBRARY_PATH="/home/cod4/server/libs:/home/cod4/server/libs/mysql"
export LD_PRELOAD="/home/cod4/server/libs/libcod4_1_7.so"

cd /home/cod4/server
./cod4_lnxded-bin +set dedicated "2" +set net_port "28961" +set fs_basepath "/home/cod4/server" +set fs_homepath "/home/cod4/server" +set fs_game "mods/nl_zom" +exec zom.cfg +map_rotate


Still nothing...

kung foo man
23rd September 2013, 00:27
Any LD warning? Post the output

BlancO
23rd September 2013, 11:50
http://pastebin.com/0xRNTTr0

kung foo man
23rd September 2013, 13:23
There is nothing in the log file, I need the Putty output ala:



k_deathrun@Debian-70-wheezy-64-LAMP:~$ ./server_zombots.sh
> [WARNING] Compiled for: 210
Compiled: Sep 17 2013 23:08:19
> [INFO] value of closer=08111d32
> [PLUGIN LOADED]
CoD2 MP 1.0 build linux-i386 Oct 24 2005
----- FS_Startup -----
Current search path:
/home/k_deathrun/zombots
/home/k_deathrun/main/iw_14.iwd (4038 files)
/home/k_deathrun/main/iw_13.iwd (22624 files)
/home/k_deathrun/main/iw_12.iwd (1016 files)
/home/k_deathrun/main/iw_11.iwd (1462 files)
/home/k_deathrun/main/iw_10.iwd (1936 files)
/home/k_deathrun/main/iw_09.iwd (2142 files)
/home/k_deathrun/main/iw_08.iwd (2723 files)
/home/k_deathrun/main/iw_07.iwd (3384 files)
/home/k_deathrun/main/iw_06.iwd (990 files)
/home/k_deathrun/main/iw_05.iwd (928 files)

BlancO
23rd September 2013, 13:58
root@mynl.pl:~# /home/cod4.sh
> [WARNING] Compiled for: COD_VERSION
> [INFO] value of closer=080c206e
CoD4 MP 1.7 build linux-i386 Jun 28 2008
begin $init
----- FS_Startup -----
Current language: english
Current search path:
/home/cod4/server/mods/nl_zom
/home/cod4/server/main/iw_13.iwd (265 files)
/home/cod4/server/main/iw_12.iwd (33 files)
/home/cod4/server/main/iw_11.iwd (448 files)
/home/cod4/server/main/iw_10.iwd (230 files)
/home/cod4/server/main/iw_09.iwd (447 files)
/home/cod4/server/main/iw_08.iwd (66 files)
/home/cod4/server/main/iw_07.iwd (34 files)
/home/cod4/server/main/iw_06.iwd (416 files)

BlancO
23rd September 2013, 18:33
console_mp.log


scriptengine> wrongs args for mysql_real_connect(...);


_config.gsc



level.mysqlUser = "user";
level.mysqlAdress = "mynl.pl";
level.mysqlPort = "3306";
level.mysqlDb = "cod4_zom";
level.mysqlPass = "pass";


mysql.gsc


host = level.mysqlAdress;
user = level.mysqlUser;
pass = level.mysqlPass;
db = level.mysqlDb;
port = level.mysqlPort;


mysql = mysql_init();

if ( ! isDefined(mysql))
{
std\io::println("mysql not defined!");
return;
}

std\io::println("mysql=" + ("2"+2) + "\n");

ret = mysql_real_connect(mysql, host, user, pass, db, port);

...

kung foo man
23rd September 2013, 18:41
port is int (a number), you would be better off just re-using the data/code-separation with cvar's

BlancO
23rd September 2013, 20:15
Thanks, for replay. After dealing with a few problems with mysql I get error:



/home/cod4.sh: line 2: 3922 Naruszenie ochrony pamięci LD_LIBRARY_PATH="/home/cod4/server/libs:/home/cod4/server/libs/mysql" LD_PRELOAD="/home/cod4/server/libs/libcod4_1_7.so" ./cod4_lnxded +set dedicated "2" +set net_port "41" +set fs_basepath "/home/cod4/server" +set fs_homepath "/home/cod4/server" +set fs_game "mods/nl_zom" +exec zom.cfg +map_rotate

English
"Naruszenie ochrony pamięci" = "Segfault" or "Segmentation fault"

After calling to MySQL query:


theQuery = "SELECT * FROM players";

kung foo man
23rd September 2013, 20:34
Most likely the result of a null pointer given to mysql_query(). You need to save the return value of mysql_init() in level.mysql e.g. and reuse it for every query.

You can just print the pointer (an int), to see its value: std\io::println("mysql pointer: " + mysql);