PDA

View Full Version : How to MySQL + COD2 ?



suck000
14th April 2016, 12:32
Step by step please :/ i want to make such commands like !login , !register , !aliases ect...

Whiskas
14th April 2016, 12:44
You want to make or get?

Check Asynchronous Mysql

https://killtube.org/showthread.php?1883-Asynchronous-mysql-queries&p=13719&viewfull=1#post13719

Add this as new gsc file into the mod folder and edit init variables at the beginning of the script.

Btw. Do you even have installed mysql?

IzNoGoD
14th April 2016, 15:24
https://killtube.org/showthread.php?1157-Scripting-FAQ-read-this-first!
Focus on the last question.

suck000
14th April 2016, 16:31
I installed phpmyadmin & mysql whiskas :p

suck000
14th April 2016, 17:20
Whiskas i got a segmentation fault when starting the server ! how to fix it ? i tried to change bind line in /etc/init.d/my.cnf to localhost & my machine ip but i still get that problem..

Whiskas
14th April 2016, 19:53
Show me your init variables.

IzNoGoD
14th April 2016, 20:13
GUYS I JUST HAD A SEGFAULT OMFG HELP ME

Provide some info dude. Read how to ask for help. Learn some scripting. Learn how to debug your own problems.

suck000
14th April 2016, 20:46
This is what i got when i debugged
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0xb71327cb in mysql_options ()
from /usr/lib/i386-linux-gnu/libmysqlclient.so.18
(gdb) bt
#0 0xb71327cb in mysql_options ()
from /usr/lib/i386-linux-gnu/libmysqlclient.so.18
#1 0xb7740cb1 in gsc_mysql_real_connect () from libcod/bin/libcod2_1_0.so
#2 0x080806a0 in ?? ()
#3 0x080838ca in ?? ()
#4 0x080839eb in ?? ()
#5 0x08115eaf in ?? ()
#6 0x0810700e in ?? ()
#7 0x08090d12 in ?? ()
#8 0x08090dbf in ?? ()
#9 0x08091f94 in ?? ()
#10 0x0808ad5f in ?? ()
#11 0x08060724 in ?? ()
#12 0x0805fc79 in ?? ()
#13 0x0808b228 in ?? ()
#14 0x08060724 in ?? ()
#15 0x0805fdf5 in ?? ()
#16 0x0805fe07 in ?? ()
#17 0x08061ff1 in ?? ()
#18 0x08062038 in ?? ()
#19 0x080d2ace in ?? ()
#20 0xb7450a83 in __libc_start_main (main=0x80d2990, argc=24, argv=0xbf8f8014,
init=0x8049b90, fini=0x8139b50, rtld_fini=0xb7779180 <_dl_fini>,

IzNoGoD
14th April 2016, 21:08
Still only giving the output, not the input.

suck000
14th April 2016, 21:15
I think i fixed it ! I changed user & pass to my username & password and it's all good ! That was the problem , i don't get segfault anymore.. how do i know that mysql is running probably ?

suck000
14th April 2016, 21:21
i get error when i try execute persistence.gsc !

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'eventAddGetMoney(name,value)
{
player = self' at line 68
help please

IzNoGoD
14th April 2016, 22:05
no.
10characters

suck000
15th April 2016, 11:40
:/
10chars

suck000
17th April 2016, 12:13
> [INFO] Compiled for: CoD2 1.0
Compiled: Apr 17 2016 11:35:22 using GCC 4.8.4
> [PLUGIN LOADED]
CoD2 MP 1.0 build linux-i386 Oct 24 2005
----- FS_Startup -----
Current search path:
/home/codserver/server/mod/zzz_all_rifles_v1.5.iwd (18 files)
/home/codserver/server/mod/oneshot.iwd (57 files)
/home/codserver/server/mod
/home/codserver/server/main/wawa.iwd (11 files)
/home/codserver/server/main/iw_14.iwd (4038 files)
/home/codserver/server/main/iw_13.iwd (22624 files)
/home/codserver/server/main/iw_12.iwd (1016 files)
/home/codserver/server/main/iw_11.iwd (1462 files)
/home/codserver/server/main/iw_10.iwd (1936 files)
/home/codserver/server/main/iw_09.iwd (2142 files)
/home/codserver/server/main/iw_08.iwd (2723 files)
/home/codserver/server/main/iw_07.iwd (3384 files)
/home/codserver/server/main/iw_06.iwd (990 files)
/home/codserver/server/main/iw_05.iwd (928 files)
/home/codserver/server/main/iw_04.iwd (698 files)
/home/codserver/server/main/iw_03.iwd (26 files)
/home/codserver/server/main/iw_02.iwd (40 files)
/home/codserver/server/main/iw_01.iwd (16 files)
/home/codserver/server/main/iw_00.iwd (102 files)
/home/codserver/server/main
/home/codserver/server/raw
/home/codserver/server/raw_shared
/home/codserver/server/devraw
/home/codserver/server/devraw_shared

File Handles:
----------------------
42211 files in iwd files
execing default_mp.cfg
couldn't exec language.cfg
execing config_mp_server.cfg
fs_homepath is write protected.
fs_game is write protected.
fs_basepath is write protected.
Opening IP socket: localhost:28960
Hostname: MyVPS
IP: 89.36.208.230
--- Common Initialization Complete ---
fs_homepath is write protected.
fs_game is write protected.
net_port is write protected.
fs_basepath is write protected.
execing server.cfg
net_ip is write protected.
net_port is write protected.
dedicated is read only.
map_rotate...

"sv_mapRotation" is:"gametype tdm map mp_toujane gametype tdm map mp_carentan gametype tdm map mp_trainstation gametype tdm map mp_decoy gametype tdm map mp_farmhouse gametype tdm map mp_burgundy gametype tdm map mp_brecourt gametype tdm map mp_railyard gametype tdm map mp_downtown gametype tdm map mp_leningrad gametype tdm map mp_dawnville gametype tdm map mp_matmata gametype tdm map mp_breakout"

"sv_mapRotationCurrent" is:""

Setting g_gametype: tdm.
Setting map: mp_toujane.
manymaps> map=mp_toujane sv_iwdNames:
manymaps> link src=/home/codserver/server/mod/Library/mp_toujane.iwd dst=/home/codserver/server/mod/mp_toujane.iwd
------ Server Initialization ------
Server: mp_toujane
----- FS_Startup -----
Current search path:
/home/codserver/server/mod/zzz_all_rifles_v1.5.iwd (18 files)
/home/codserver/server/mod/oneshot.iwd (57 files)
/home/codserver/server/mod
/home/codserver/server/main/wawa.iwd (11 files)
/home/codserver/server/main/iw_14.iwd (4038 files)
/home/codserver/server/main/iw_13.iwd (22624 files)
/home/codserver/server/main/iw_12.iwd (1016 files)
/home/codserver/server/main/iw_11.iwd (1462 files)
/home/codserver/server/main/iw_10.iwd (1936 files)
/home/codserver/server/main/iw_09.iwd (2142 files)
/home/codserver/server/main/iw_08.iwd (2723 files)
/home/codserver/server/main/iw_07.iwd (3384 files)
/home/codserver/server/main/iw_06.iwd (990 files)
/home/codserver/server/main/iw_05.iwd (928 files)
/home/codserver/server/main/iw_04.iwd (698 files)
/home/codserver/server/main/iw_03.iwd (26 files)
/home/codserver/server/main/iw_02.iwd (40 files)
/home/codserver/server/main/iw_01.iwd (16 files)
/home/codserver/server/main/iw_00.iwd (102 files)
/home/codserver/server/main
/home/codserver/server/raw
/home/codserver/server/raw_shared
/home/codserver/server/devraw
/home/codserver/server/devraw_shared

File Handles:
----------------------
42211 files in iwd files
------- Game Initialization -------
gamename: Call of Duty 2
gamedate: Oct 24 2005
----------------------
Game: G_SetupWeaponDef
----------------------

******* script compile error *******
unknown function: (file 'maps/mp/gametypes/_mysql.gsc', line 145)
return mysql_real_escape_string(level.JH_mysql, string);
*
************************************
Sys_Error: Error during initialization:
script compile error
(see console for details)

i get this error when starting my server with mysql

_mysql.gsc file :
init()
{
//get your host, user, pass, db, port here
level.JH_mysql = mysql_reuse_connection();
if(!isDefined(level.JH_mysql))
level.JH_mysql = initMySQL("localhost", "myuserhere", "mypasshere", "mydbhere", 3306);
initAsyncMySQL("localhost", "myuserhere", "mypasshere", "mydbhere", 3306);
}

query(query)
{
if(!isDefined(level.JH_mysql))
return undefined;
result = mysql_query(level.JH_mysql, query);
resettimeout();
if(result)
{
printf("Error in " + query + "\n");
return undefined;
}
result = mysql_store_result(level.JH_mysql);
rows = getRows(result);
return rows;
}

queryNosave(query)
{
if(!isDefined(level.JH_mysql))
return undefined;
result = mysql_query(level.JH_mysql, query);
resettimeout();
if(result)
{
printf("Error in " + query + "\n");
return undefined;
}
return [];
}

getRows(result)
{
if(!isDefined(result))
return [];
rowcount = mysql_num_rows(result);
fields = [];
field = mysql_fetch_field(result);
while(isDefined(field))
{
fields[fields.size] = field;
field = mysql_fetch_field(result);
}
rows = [];
for(i = 0; i < rowcount; i++)
{
row = mysql_fetch_row(result);
rows[rows.size] = [];
for(j = 0; j < fields.size; j++)
rows[rows.size - 1][fields[j]] = row[j];
}
mysql_free_result(result);
return rows;
}

asyncQuery(query, function, args)
{
id = mysql_async_createQuery(query);
task = spawnstruct();
task.query = query;
task.invoker = self;
task.function = function;
task.args = args;
level.JH_mysqlAsync["" + id] = task;
}

asyncQueryNosave(query, function, args)
{
id = mysql_async_createQueryNosave(query);
task = spawnstruct();
task.query = query;
task.invoker = self;
task.function = function;
task.args = args;
level.JH_mysqlAsync["" + id] = task;
}

initAsyncMySQL(host, user, pass, db, port)
{
mysql_async_initializer(host, user, pass, db, port, 4);
level.JH_mysqlAsync = [];
thread loopAsyncMySQL();
}

loopAsyncMySQL()
{
while(true)
{
list = mysql_async_GetDoneList();
for(i = 0; i < list.size; i++)
{
result = mysql_async_getResultAndFree(list[i]);
if(!isdefined(result))
continue;
if(result == 0)
result = undefined;
task = "" + list[i];
if(isDefined(level.JH_mysqlAsync[task]))
{
if(isDefined(level.JH_mysqlAsync[task].function))
{
if(isDefined(level.JH_mysqlAsync[task].invoker))
{
rows = getRows(result);
level.JH_mysqlAsync[task].invoker thread [[level.JH_mysqlAsync[task].function]](rows, level.JH_mysqlAsync[task].args);
}
else if(isDefined(result))
mysql_free_result(result);
}
else if(isDefined(result))
mysql_free_result(result);
}
else if(isDefined(result))
mysql_free_result(result);
level.JH_mysqlAsync[task] = undefined;
}
wait .05;
}
}

initMySQL(host, user, pass, db, port)
{
mysql = mysql_init();
ret = mysql_real_connect(mysql, host, user, pass, db, port);
if(!ret)
{
printf("errno=" + mysql_errno(mysql) + " error= " + mysql_error(mysql) + "\n");
mysql_close(mysql);
return undefined;
}
return mysql;
}

stripString(string)
{
if(isDefined(level.JH_mysql))
return mysql_real_escape_string(level.JH_mysql, string);
return "";
}

I added _mysql to Callback_StartGameType already :

thread map\mp\gametype\_mysql::init();

Am using mitch libcod and already mysqllibcod installed .. what is the problem !

IzNoGoD
17th April 2016, 12:45
You're using a libcod version thats compiled without mysql support it seems.

suck000
17th April 2016, 12:52
I downloaded a 2015-Jan-29 01:25:40 copy and placed it on libcod/bin folder , by the way am using mitch's libcod.

Also , that problem that i wrote earlier on disappeard right now when i replaced the 2015-Jan-29 01:25:40 libcod2_1_0 but i got a new one :S



******* script compile error *******
unknown function: (file 'maps/mp/gametypes/_mysql.gsc', line 100)
result = mysql_async_getResultAndFree(list[i]);
*
************************************
Sys_Error: Error during initialization:
script compile error
(see console for details)

IzNoGoD
17th April 2016, 13:03
Yep, those are functions renamed by me in my own libcod. Rename it back to mysql_async_get_result_and_free

Same for other camelCase functions you find non-existing.

suck000
17th April 2016, 13:07
Am going to delete mitch libcod and install yours. It will work than right ?

suck000
17th April 2016, 13:25
No more mysql errors ! but i get unknown fuction in all my functions on _callbacksetup.gsc file :O

Am using iznogod libcod.

IzNoGoD
17th April 2016, 14:13
I never made my libcod publicly available, so I'm curious how you're running "my libcod"

suck000
17th April 2016, 14:58
https://github.com/iznogod/libcod o.O

IzNoGoD
17th April 2016, 15:58
That one is hopelessly outdated and unmaintained. Didnt even know I still had it.

When you look at this forum, there's a libcod sub-forum. Below that link, there's links to 3 libcod distributions. Use mitch or voron's versions.

This has also been explained in the how-to-set-up-libcod-on-ubuntu topic.

suck000
17th April 2016, 16:00
Everything is good with mysql now .. no errors anymore but on what can i use it ?

suck000
17th April 2016, 16:04
Check this thread :P https://killtube.org/showthread.php?2601-What-can-i-do-with-MySQL-Now-D