0 Members and 1 Guest are viewing this topic.
#include <stdio.h>#include "mysql.h"#include <string>#include <sstream>std::string CheckAccount(std::string Name){ MYSQL_RES *result; MYSQL_ROW row; MYSQL *connection, mysql; int state; std::string w; std::stringstream tmp; w=""; mysql_init(&mysql); connection=mysql_real_connect(&mysql,"host","user","pass","database",0,0,0); if(connection==NULL) { return ""; } state = mysql_query(connection, ("SELECT A,B FROM Table WHERE X='"+Name+"'").c_str()); if(state!=0) { return ""; } result = mysql_store_result(connection); while((row=mysql_fetch_row(result))!=NULL) { tmp << (row[0] ? row[0] : "NULL") << "_" << (row[1] ? row[1] : "NULL"); } w = tmp.str(); mysql_free_result(result); mysql_close(connection); return w;}
function Check(Name: string): string;external 'CheckAccount@lib.so;procedure OnJoinGame(ID, Team: byte);vardane: string;begin dane:=Check(GetPlayerStat(ID,'Name')); WriteLn(dane);end;
[12-03-31 17:27] * Mr: SyavX: When sending strings around between Delphi and C, you need to do a bit of memory management yourself.[12-03-31 17:28] * Mr: Here's what will not work:[12-03-31 17:28] * Mr: Passing strings from the script core to an exported function taking std::string as argument[12-03-31 17:28] * Mr: Using C strings from the script core after the script function returned - copy the string instead[12-03-31 17:28] * Mr: Using the string type in the script core to pass something to a function that exports char* (it will mess with the reference counter)[12-03-31 17:47] * Mr: SyavX: http://codepad.org/iL0EzIMJ[12-03-31 17:48] * Mr: To make things easier when returning strings from C to Delphi/Pascal, you can copy the returned string into managed memory (string type in Delphi), free it afterwards and just continue using the string.
external 'CheckAccount@lib.so;
So I've put that library in soldatserver root directory and wrote a script that makes use of it but when server starts I get "Unable to find variable" error. Following http://devs.soldat.pl/wiki/index.php?title=Using_DLLs I exported LD_LIBRARY_PATH (export LD_LIBRARY_PATH=/path/to/soldatserver) but that didn't help either.