chuyiwen_gmsv/sasql.c
chuyiwen bea5ac05b3 sq_gmsv_chuyiwen
sa_sever
2016-12-24 09:45:52 +09:00

2061 lines
55 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#define _SASQL_C_
#include "version.h"
//#include "main.h"
#include "sasql.h"
#include "net.h"
#include "common.h"
#include "char_base.h"
#include "char_data.h"
#include "char.h"
#include "lssproto_serv.h"
#include "item.h"
#include "item_event.h"
#include "buf.h"
#include "object.h"
#include "map_deal.h"
#include "saacproto_cli.h"
#include "readmap.h"
#include "handletime.h"
#include "char_event.h"
#include "npccreate.h"
#include "addressbook.h"
#include "item_event.h"
#include "magic_base.h"
#include "magic.h"
#include "chatmagic.h"
#include "configfile.h"
#include "log.h"
#include "anim_tbl.h"
#include "encount.h"
#include "battle.h"
#include "pet_skill.h"
#include "util.h"
#include "enemy.h"
#include "npcutil.h"
#include "pet.h"
#include "family.h"
#include "defend.h"
#include "correct_bug.h"
#include <mysql/mysql.h>
extern int fmrankindex[20];
extern char fmrankname[20][50];
extern int fmrankpoint[20];
MYSQL mysql;
MYSQL serversql;
MYSQL_RES *mysql_result;
MYSQL_ROW mysql_row;
void easyGetTokenFromString2( char *src,int count,char*output,int len )
{
int i;
int counter = 0;
if( len <= 0 )return;
#define ISSPACETAB( c ) ( (c) == ' ' || (c) == '\t' )
for(i=0;;i++){
if( src[i]=='\0'){
output[0] = '\0';
return;
}
if( i > 0 && ! ISSPACETAB( src[i-1] ) &&
! ISSPACETAB( src[i] ) ){
continue;
}
if( ! ISSPACETAB( src[i]) ){
counter++;
if( counter == count){
int j;
for(j=0;j<len-1;j++){
if( src[i+j] == '\0' ||
ISSPACETAB( src[i+j] ) ){
break;
}
output[j]=src[i+j];
}
output[j]='\0';
return;
}
}
}
}
typedef struct tagConfig
{
char sql_IP[16];
int sql_Port;
char sql_Port1[16];
char sql_ID[16];
char sql_PS[16];
char sql_DataBase[16];
char sql_Table[16];
char sql_LOCK[16];
char sql_NAME[16];
char sql_PASS[16];
}Config;
Config sqlconfig;
int AutoReg = 0;
int openbackground;
int sameipnum = 0;
static int readConfig( char *path )
{
char buf[255];
FILE *fp;
fp = fopen( path , "r" );
if( fp == NULL ){ return -2; }
while( fgets( buf , sizeof( buf ) , fp )){
char command[255];
char param[255];
chop(buf);
easyGetTokenFromString2( buf , 1 , command , sizeof( command ));
easyGetTokenFromString2( buf , 2 , param , sizeof( param ));
if( strcmp( command , "sql_IP" ) == 0 ){
strcmp( sqlconfig.sql_IP , param ) ;
snprintf( sqlconfig.sql_IP , sizeof( sqlconfig.sql_IP) , param );
printf("\n<EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD> %s",sqlconfig.sql_IP);
} else if( strcmp( command , "sql_Port" ) == 0 ){
sqlconfig.sql_Port = atoi( param );
snprintf( sqlconfig.sql_Port1 , sizeof( sqlconfig.sql_Port1) , param );
printf("\n<EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD>˿ڣ<EFBFBD> %d",sqlconfig.sql_Port);
} else if( strcmp( command , "sql_ID" ) == 0 ){
strcmp( sqlconfig.sql_ID , param ) ;
snprintf( sqlconfig.sql_ID , sizeof( sqlconfig.sql_ID) , param );
printf("\n<EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD> %s",sqlconfig.sql_ID);
} else if( strcmp( command , "sql_PS" ) == 0 ){
strcmp( sqlconfig.sql_PS , param ) ;
snprintf( sqlconfig.sql_PS , sizeof( sqlconfig.sql_PS) , param );
printf("\n<EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>룺 %s",sqlconfig.sql_PS);
} else if( strcmp( command , "sql_DataBase" ) == 0 ){
strcmp( sqlconfig.sql_DataBase , param ) ;
snprintf( sqlconfig.sql_DataBase , sizeof( sqlconfig.sql_DataBase) , param );
printf("\n<EFBFBD><EFBFBD>½<EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%s",sqlconfig.sql_DataBase);
} else if( strcmp( command , "sql_Table" ) == 0 ){
strcmp( sqlconfig.sql_Table , param ) ;
snprintf( sqlconfig.sql_Table , sizeof( sqlconfig.sql_Table) , param );
printf("\n<EFBFBD>û<EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> %s",sqlconfig.sql_Table);
} else if( strcmp( command , "sql_LOCK" ) == 0 ){
strcmp( sqlconfig.sql_LOCK , param ) ;
snprintf( sqlconfig.sql_LOCK , sizeof( sqlconfig.sql_LOCK) , param );
printf("\n<EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> %s",sqlconfig.sql_LOCK);
} else if( strcmp( command , "sql_NAME" ) == 0 ){
strcmp( sqlconfig.sql_NAME , param ) ;
snprintf( sqlconfig.sql_NAME , sizeof( sqlconfig.sql_NAME) , param );
printf("\n<EFBFBD>˺<EFBFBD><EFBFBD>ֶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD> %s",sqlconfig.sql_NAME);
} else if( strcmp( command , "sql_PASS" ) == 0 ){
strcmp( sqlconfig.sql_PASS , param ) ;
snprintf( sqlconfig.sql_PASS , sizeof( sqlconfig.sql_PASS) , param );
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD> %s",sqlconfig.sql_PASS);
} else if( strcmp( command , "openbackground" ) == 0 ){
openbackground = atoi( param );
if(openbackground){
printf("\n<EFBFBD><EFBFBD>̨<EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD> YES");
}else{
printf("\n<EFBFBD><EFBFBD>̨<EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD> NO");
}
} else if( strcmp( command , "AutoReg" ) == 0 ){
AutoReg = atoi( param );
if(AutoReg){
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD>ע<EFBFBD>᣺YES");
}else{
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD>ע<EFBFBD>᣺NO");
}
} else if( strcmp( command , "SameIpNum" ) == 0 ){
sameipnum = atoi( param );
}
}
fclose(fp);
return 0;
}
BOOL sasql_init( void )
{
if( mysql_init(&mysql) == NULL & readConfig("sql.cf"))
{
printf("\n<EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>");
exit(1);
return FALSE;
}
if( !mysql_real_connect( &mysql,
sqlconfig.sql_IP,
sqlconfig.sql_ID,//<2F>ʺ<EFBFBD>
sqlconfig.sql_PS,//<2F><><EFBFBD><EFBFBD>
sqlconfig.sql_DataBase,//ѡ<><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͽ<EFBFBD>
sqlconfig.sql_Port,
NULL,
0 ) )
{
printf("\n<EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>\n");
return FALSE;
}
printf("\n<EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳɹ<EFBFBD><EFBFBD><EFBFBD>\n");
return TRUE;
}
int sasql_mysql_query( char *sqlstr )
{
mysql_query(&mysql,"set names 'gbk'");
return mysql_query(&mysql,sqlstr);
}
void sasql_close( void )
{
mysql_close( &mysql );
}
int sasql_query(char *nm, char *pas){
char sqlstr[256];
sprintf(sqlstr,"select `%s`,`%s`,`SafePasswd`,`Lock` from `%s` where `%s`=BINARY'%s'",sqlconfig.sql_NAME,sqlconfig.sql_PASS,sqlconfig.sql_Table,sqlconfig.sql_NAME,nm);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
if(mysql_row[2]!=NULL){
if((strcmp(pas,mysql_row[1]) == 0) && (atoi(mysql_row[3])==0 || atoi(mysql_row[3])==getLockType())){
return 1;
}else{
//printf("<22>û<EFBFBD>%s<><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n",nm);
return 2;
}
}else
{
if(strcmp(pas,mysql_row[1]) == 0 && atoi(mysql_row[3])==0){
return 1;
}else{
//printf("<22>û<EFBFBD>%s<><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n",nm);
return 2;
}
}
}else{
mysql_free_result(mysql_result);
//printf("<22>û<EFBFBD>%sδע<CEB4>ᣡ\n",nm);
return 3;
}
}else{
//printf("\n<><6E><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>\n");
return 0;
}
}
int sasql_load_query(char *nm, char *pas){
char sqlstr[256];
sprintf(sqlstr,"select `%s`,`%s` from `%s` where `%s`=BINARY'%s'",sqlconfig.sql_NAME,sqlconfig.sql_PASS,sqlconfig.sql_Table,sqlconfig.sql_NAME,nm);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
if(strcmp(pas,mysql_row[1]) == 0){
return 1;
}else{
printf("<EFBFBD>û<EFBFBD>%s<><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n",nm);
return 2;
}
}else{
mysql_free_result(mysql_result);
printf("<EFBFBD>û<EFBFBD>%sδע<CEB4>\n",nm);
return 3;
}
}else{
printf("\n<EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>\n");
return 0;
}
}
int sasql_del_query(char *nm, char *pas){
char sqlstr[256];
sprintf(sqlstr,"select `%s`,`SafePasswd` from `%s` where `%s`=BINARY'%s'",sqlconfig.sql_NAME,sqlconfig.sql_Table,sqlconfig.sql_NAME,nm);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
if(mysql_row[1]!=NULL)
{
if(strcmp(pas,mysql_row[1]) == 0){
return 1;
}else{
return 2;
}
}else{
printf("<EFBFBD>û<EFBFBD>%s<><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n",nm);
return 2;
}
}else{
mysql_free_result(mysql_result);
printf("<EFBFBD>û<EFBFBD>%sδע<CEB4>\n",nm);
return 3;
}
}else{
printf("\n<EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>\n");
return 0;
}
}
BOOL sasql_online( char *ID, char *NM, char *IP,int fame,int vigor, int flag )
{
if(openbackground){
char sqlstr[256];
if(flag==0)
sprintf(sqlstr,"update `%s` set `Online`=0,`Offline`=0 where `%s`=BINARY'%s'", sqlconfig.sql_Table, sqlconfig.sql_NAME, ID);
else if(flag==1)
{
if(strstr(NM,",")!=NULL) return FALSE;
mysql_query(&mysql,"SET NAMES 'gbk'");
sprintf(sqlstr,"update `%s` set `LoginTime`=NOW(), `IP`='%s', `OnlineName`='%s', `Online`=%d, `Path`='char/0x%x',`Fame`=%d,`Vigor`=%d where `%s`=BINARY'%s'", sqlconfig.sql_Table, IP, NM, getServernumber(), getHash(ID) & 0xff,fame,vigor, sqlconfig.sql_NAME, ID);
}
else if(flag==2){
if(strstr(NM,",")!=NULL) return FALSE;
sprintf(sqlstr,"update `%s` set `LoginTime`=NOW(), `OnlineName`='%s', `Online`=%d where `%s`=BINARY'%s'", sqlconfig.sql_Table, NM, getServernumber(), sqlconfig.sql_NAME, ID);
}
else if(flag==3)
sprintf(sqlstr,"update `%s` set `Online`=0,`Offline`=0 where `Online`=%d", sqlconfig.sql_Table, getServernumber());
else if(flag==4)
sprintf(sqlstr,"update `%s` set `LoginTime`=NOW(),`IP`='%s', `Online`=%d where `%s`=BINARY'%s'", sqlconfig.sql_Table, IP, getServernumber(), sqlconfig.sql_NAME, ID);
else if(flag==5)
sprintf(sqlstr,"update `%s` set `Offline`=1 where `%s`=BINARY'%s'", sqlconfig.sql_Table, sqlconfig.sql_NAME, ID);
if(!mysql_query(&mysql,sqlstr)){
return TRUE;
}
}
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>\n");
return FALSE;
}
/*
BOOL sasql_online_jqm( char *ID, char *jqm, char *IP, int logintype, char *GHid, char *GHic, char *GHsp )
{
if(openbackground){
char sqlstr[2048];
if(strstr(jqm,",")!=NULL || strstr(jqm,"+")!=NULL || strstr(jqm,"?")!=NULL || strstr(jqm,"*")!=NULL || strstr(jqm,"<")!=NULL || strstr(jqm,")")!=NULL || strstr(jqm,"^")!=NULL || strstr(jqm,"`")!=NULL || strstr(jqm,";")!=NULL)
sprintf(sqlstr,"update `%s` set `LoginTime`=NOW(),`IP`='%s',`PcId`='CUOWU', `Online`=%d,`Type`=%d,`GHid`='%s',`GHic`='%s',`GHsp`='%s' where `%s`=BINARY'%s'", sqlconfig.sql_Table, IP, getServernumber(),logintype,GHid,GHic,GHsp, sqlconfig.sql_NAME, ID);
else
sprintf(sqlstr,"update `%s` set `LoginTime`=NOW(),`IP`='%s',`PcId`='%s', `Online`=%d,`Type`=%d,`GHid`='%s',`GHic`='%s',`GHsp`='%s' where `%s`=BINARY'%s'", sqlconfig.sql_Table, IP,jqm, getServernumber(),logintype,GHid,GHic,GHsp, sqlconfig.sql_NAME, ID);
//print("\n sql: %s",sqlstr);
if(!mysql_query(&mysql,sqlstr)){
return TRUE;
}
}
printf("\n<><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>\n");
return FALSE;
}
*/
BOOL sasql_online_jqm( char *ID, char *jqm, char *IP,int logintype )
{
if(openbackground){
char sqlstr[256];
if(strstr(jqm,",")!=NULL || strstr(jqm,"+")!=NULL || strstr(jqm,"?")!=NULL || strstr(jqm,"*")!=NULL || strstr(jqm,"<")!=NULL || strstr(jqm,")")!=NULL || strstr(jqm,"^")!=NULL || strstr(jqm,"`")!=NULL || strstr(jqm,";")!=NULL)
sprintf(sqlstr,"update `%s` set `LoginTime`=NOW(),`IP`='%s',`PcId`='CUOWU', `Online`=%d,`Type`=%d where `%s`=BINARY'%s'", sqlconfig.sql_Table, IP, getServernumber(),logintype, sqlconfig.sql_NAME, ID);
else
sprintf(sqlstr,"update `%s` set `LoginTime`=NOW(),`IP`='%s',`PcId`='%s', `Online`=%d,`Type`=%d where `%s`=BINARY'%s'", sqlconfig.sql_Table, IP,jqm, getServernumber(),logintype, sqlconfig.sql_NAME, ID);
//print("\n sql: %s",sqlstr);
if(!mysql_query(&mysql,sqlstr)){
return TRUE;
}
}
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>\n");
return FALSE;
}
#ifdef _CAX_NEWMAC_LOGIN
BOOL sasql_online_mac( char *ID, char *mac, char *IP,int logintype )
{
// if(openbackground){
char sqlstr[256];
sprintf(sqlstr,"update `%s` set `LoginTime`=NOW(),`IP`='%s',`MAC`='%s', `Online`=%d where `%s`=BINARY'%s'", sqlconfig.sql_Table, IP, mac , getServernumber(), sqlconfig.sql_NAME, ID);
if(!sasql_mysql_query(sqlstr)){
return TRUE;
}
// }
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>ʧ<EFBFBD><EFBFBD>[mac]<5D><>\n");
return FALSE;
}
#endif
BOOL sasql_register(char *id, char *ps)
{
char sqlstr[256];
if(AutoReg!=1)return FALSE;
sprintf(sqlstr,"INSERT INTO `%s` (`%s`,`%s`,`RegTime`,`Path`,`VipPoint`) VALUES (BINARY'%s','%s',NOW(),'char/0x%x',0)",sqlconfig.sql_Table, sqlconfig.sql_NAME, sqlconfig.sql_PASS, id, ps, getHash(id) & 0xff);
if(!mysql_query(&mysql,sqlstr)){
printf("\n<EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>ע<EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>\n");
return TRUE;
}
printf("\n<EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>ע<EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>\n");
return FALSE;
}
BOOL sasql_chehk_lock( char *idip )
{
char sqlstr[256];
sprintf(sqlstr,"select * from `%s` where `%s`=BINARY'%s'", sqlconfig.sql_LOCK, sqlconfig.sql_NAME, idip);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
mysql_free_result(mysql_result);
if(num_row>0)
{
return TRUE;
}
else
{
return FALSE;
}
}
return FALSE;
}
BOOL sasql_add_lock( char *idip )
{
char sqlstr[256];
sprintf(sqlstr,"INSERT INTO `%s` (`%s`) VALUES (BINARY'%s')", sqlconfig.sql_LOCK, sqlconfig.sql_NAME, idip);
if(!mysql_query(&mysql,sqlstr)){
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%s<>ɹ<EFBFBD><C9B9><EFBFBD>\n",idip);
return TRUE;
}
return FALSE;
}
BOOL sasql_del_lock( char *idip )
{
char sqlstr[256];
sprintf(sqlstr,"delete from `%s` where `%s`=BINARY'%s'", sqlconfig.sql_LOCK, sqlconfig.sql_NAME, idip);
if(!mysql_query(&mysql,sqlstr)){
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%s<>ɹ<EFBFBD><C9B9><EFBFBD>\n",idip);
return TRUE;
}
return FALSE;
}
int sasql_vippoint( char *ID, int point, int flag )
{
char sqlstr[256];
// print("\NVIPpoint1=%d\n",point);
if(strstr(ID,"'")!=NULL) return -1;
sprintf(sqlstr,"select `VipPoint` from `%s` where `%s`=BINARY'%s'",sqlconfig.sql_Table,sqlconfig.sql_NAME,ID);
// printf("22222222:%s\n",sqlstr);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
if(flag==0){
return atoi(mysql_row[0]);
}
if(flag==520){
sprintf(sqlstr,"update `%s` set `VipPoint`=%d where `%s`=BINARY'%s'", sqlconfig.sql_Table, point,sqlconfig.sql_NAME, ID);
}else{
point+=atoi(mysql_row[0]);
sprintf(sqlstr,"update `%s` set `VipPoint`=%d where `%s`=BINARY'%s'", sqlconfig.sql_Table, point,sqlconfig.sql_NAME, ID);
}
// printf("33333333:%s\n",sqlstr);
if(!mysql_query(&mysql,sqlstr)){
return point;
}else{
return atoi(mysql_row[0]);
}
}else{
mysql_free_result(mysql_result);
}
}
printf("<EFBFBD><EFBFBD><EFBFBD>»<EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>-- %s\n",sqlstr);
return -1;
}
int sasql_onlinenum( char *cdkey, char *IP )
{
char sqlstr[256];
sprintf(sqlstr,"select * from `%s` where `%s`='%s' and `Online`>0 and `IP`='%s'",sqlconfig.sql_Table,sqlconfig.sql_NAME,cdkey,IP);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
mysql_free_result(mysql_result);
if(num_row>0){
return 0;
}
}
sprintf(sqlstr,"select count(*) from `%s` where `Online`>0 and `Offline`=0 and `IP`='%s'",sqlconfig.sql_Table,IP);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
return atoi(mysql_row[0]);
}else{
mysql_free_result(mysql_result);
}
}
return 0;
}
int sasql_onlinejqmnum( char *jqm, int flag )
{
char sqlstr[256];
// sprintf(sqlstr,"select * from `%s` where `%s`='%s' and `Online`>0 and `PcId`='%s'",sqlconfig.sql_Table,sqlconfig.sql_NAME,cdkey,jqm);
// if(!mysql_query(&mysql,sqlstr)){
// int num_row=0;
// mysql_result=mysql_store_result(&mysql);
// num_row=mysql_num_rows(mysql_result);
// mysql_free_result(mysql_result);
// if(num_row>0){
// return 0;
// }
// }
if(flag == 1){
sprintf(sqlstr,"select count(*) from `%s` where `Online`=%d and `Offline`=0 and `PcId`='%s'",sqlconfig.sql_Table,getServernumber(),jqm);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
return atoi(mysql_row[0]);
}else{
mysql_free_result(mysql_result);
}
}
}else{
sprintf(sqlstr,"select count(*) from `%s` where `Online`>0 and `Offline`=0 and `PcId`='%s'",sqlconfig.sql_Table,jqm);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
return atoi(mysql_row[0]);
}else{
mysql_free_result(mysql_result);
}
}
}
return 0;
}
#ifdef _CAX_NEWMAC_LOGIN
int sasql_onlinemacnum( char *mac, int flag )
{
char sqlstr[256];
if(flag == 1){
sprintf(sqlstr,"select count(*) from `%s` where `Online`=%d and `MAC`='%s'",sqlconfig.sql_Table,getServernumber(),mac);
if(!sasql_mysql_query(sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
return atoi(mysql_row[0]);
}else{
mysql_free_result(mysql_result);
}
}
}else{
sprintf(sqlstr,"select count(*) from `%s` where `Online`>0 and `MAC`='%s'",sqlconfig.sql_Table,mac);
if(!sasql_mysql_query(sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
return atoi(mysql_row[0]);
}else{
mysql_free_result(mysql_result);
}
}
}
return 0;
}
#endif
int sasql_query_safepasswd(char *id, char *safepasswd){
char sqlstr[256];
sprintf(sqlstr,"select `SafePasswd` from `%s` where `%s`=BINARY'%s'",sqlconfig.sql_Table,sqlconfig.sql_NAME,id);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
if(mysql_row[0]!=NULL)
{
if(strcmp(safepasswd,mysql_row[0]) == 0)
{
if(strstr(id,safepasswd)!=NULL)
return 4;
return 1;
}
else
{
printf("\n<EFBFBD><EFBFBD>ȫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
return 2;
}
}
else
{
printf("\n<EFBFBD>û<EFBFBD>δ<EFBFBD><EFBFBD>д<EFBFBD><EFBFBD>ȫ<EFBFBD>\n");
return 3;
}
}else{
mysql_free_result(mysql_result);
}
}
else{
printf("\n<EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>\n");
return 0;
}
}
int sasql_add_safepasswd(char *id, char *safepasswd){
char sqlstr[256];
if(strstr(safepasswd,",")!=NULL) return 0;
sprintf(sqlstr,"update `%s` set `SafePasswd`=BINARY'%s' where `%s`=BINARY'%s'",sqlconfig.sql_Table,safepasswd,sqlconfig.sql_NAME,id);
if(!mysql_query(&mysql,sqlstr)){
printf("<EFBFBD>û<EFBFBD>%s<><73><EFBFBD>ð<EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD>\n",id);
return 1;
}else{
printf("\n<EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>\n");
return 0;
}
}
BOOL sasql_add_card(char *pas, int num)
{
char sqlstr[256];
sprintf(sqlstr,"INSERT INTO `OnlineCost` (`CostPasswd`,`CostVal`) VALUES (BINARY'%s','%d')", pas, num);
if(!mysql_query(&mysql,sqlstr)){
return TRUE;
}
return FALSE;
}
void sasql_query_card(char *id, char *cardps,int charaindex){
char sqlstr[256];
if(strstr(id,",")!=NULL){
CHAR_talkToCli( charaindex, -1, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˺ŷǷ<EFBFBD><EFBFBD><EFBFBD>", CHAR_COLORRED);
return;
}
if(strlen(cardps)!=16){
CHAR_talkToCli( charaindex, -1, "<EFBFBD><EFBFBD><EFBFBD>ܲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڡ<EFBFBD>", CHAR_COLORRED);
return;
}
if( strstr(cardps,"/")!=NULL || strstr(cardps,"*")!=NULL || strstr(cardps,"+")!=NULL || strstr(cardps,"-")!=NULL || strstr(cardps,";")!=NULL || strstr(cardps,":")!=NULL || strstr(cardps," ")!=NULL || strstr(cardps,"|")!=NULL || strstr(cardps,".")!=NULL || strstr(cardps,",")!=NULL || strstr(cardps,"'")!=NULL || strstr(cardps,"=")!=NULL || strstr(cardps,"`")!=NULL || strstr(cardps,"<")!=NULL || strstr(cardps,">")!=NULL || strstr(cardps,"!")!=NULL || strstr(cardps,"NULL")!=NULL){
CHAR_talkToCli( charaindex, -1, "<EFBFBD><EFBFBD><EFBFBD>ܷǷ<EFBFBD><EFBFBD><EFBFBD>", CHAR_COLORRED);
return;
}
sprintf(sqlstr,"select * from `OnlineCost` where `CostPasswd`=BINARY'%s'",cardps);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
int check,costval;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
check = atoi(mysql_row[4]);
costval = atoi(mysql_row[1]);
if(check == 1)
{
sprintf(sqlstr,"update `OnlineCost` set `cdkey`=BINARY'%s', `CostTime`=NOW(), `check`=0 where `CostPasswd`=BINARY'%s'",id,cardps);
if(!mysql_query(&mysql,sqlstr)){
sprintf(sqlstr,"%d<>ֽ<EFBFBD><D6BD><EFBFBD>ֵ<EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5>ֽ<EFBFBD><D6BD>ʻ<EFBFBD><CABB><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>%d",costval,sasql_rmbpoint(id,costval,1));
CHAR_talkToCli( charaindex, -1, sqlstr, CHAR_COLORRED);
}
}
else
{
CHAR_talkToCli( charaindex, -1, "<EFBFBD>ó<EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ã<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD>ʹ<EFBFBD>ã<EFBFBD>лл<EFBFBD><EFBFBD>", CHAR_COLORRED); //<2F><>ֵ<EFBFBD><D6B5><EFBFBD>Ѿ<EFBFBD>ʹ<EFBFBD><CAB9>
return;
}
}
else
{
mysql_free_result(mysql_result);
CHAR_talkToCli( charaindex, -1, "<EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD>", CHAR_COLORRED); //<2F><>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>
return;
}
}
else{
printf("\n<EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>\n");
return;
}
}
#ifdef _ONLINE_SHOP
int sasql_chehk_shop( char *dataname )
{
char sqlstr[256];
sprintf(sqlstr,"select * from `%s`", dataname);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
mysql_free_result(mysql_result);
return num_row;
}
return 0;
}
char* sasql_query_shop( char *dataname, int startrow, int shopnum )
{
char sqlstr[256];
char shopresult[2048];
int i;
sprintf(sqlstr,"select * from `%s` LIMIT %d , %d", dataname, startrow, shopnum);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
for(i=1;i<=shopnum;i++)
{
mysql_row=mysql_fetch_row(mysql_result);
if(i==1)
{
sprintf(shopresult,"%s#%s#%s#%s#%s#%s#%s|",mysql_row[0],mysql_row[1],mysql_row[2],mysql_row[3],mysql_row[4],mysql_row[5],mysql_row[6]);
}
else
{
sprintf(shopresult,"%s%s#%s#%s#%s#%s#%s#%s|",shopresult,mysql_row[0],mysql_row[1],mysql_row[2],mysql_row[3],mysql_row[4],mysql_row[5],mysql_row[6]);
}
}
mysql_free_result(mysql_result);
return shopresult;
}else
{
mysql_free_result(mysql_result);
return "err";
}
}
return "err";
}
int sasql_buy_shop( char *dataname, int startrow, int shopnum, int shopno )
{
char sqlstr[256];
int i,costnum;
sprintf(sqlstr,"select * from `%s` where `id`=%d", dataname, shopno);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
costnum = atoi(mysql_row[5])*atoi(mysql_row[4])/100;
return costnum;
}else
{
mysql_free_result(mysql_result);
return 0;
}
}
return 0;
}
#endif
char* sasql_query_question(void)
{
char sqlstr[256];
sprintf(sqlstr,"select * from `Question`");
if(!mysql_query(&mysql,sqlstr))
{
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
mysql_free_result(mysql_result);
if(num_row>0)
{
srand((unsigned)time(NULL));
int questionid;
questionid = (rand() % num_row)+1;
sprintf(sqlstr,"select * from `Question` where `id`=%d",questionid);
if(!mysql_query(&mysql,sqlstr))
{
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0)
{
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
char question[256];
sprintf(question,"%s;%s",mysql_row[1],mysql_row[2]);
return question;
}
return "err";
}
return "err";
}
return "err";
}
return "err";
}
#ifdef _ALL_ITEM
int sasql_allnum( int flag, int num, int flag1 )
{
char sqlstr[256];
sprintf(sqlstr,"select * from `AllNum` where `id`=%d",flag);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
if(flag1==0){
return atoi(mysql_row[1]);
}
num+=atoi(mysql_row[1]);
sprintf(sqlstr,"update `AllNum` set `num`=%d where `id`=%d", num,flag);
if(!mysql_query(&mysql,sqlstr)){
return num;
}
}
}
return num;
}
#endif
BOOL sasql_craete_lock( void )
{
}
BOOL sasql_craete_userinfo( void )
{
}
#ifdef _SQL_BUY_FUNC
char *sasql_OnlineBuy( char *id, char *costpasswd )
{
char sqlstr[256];
if(strstr(id,",")!=NULL) return "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˺ŷǷ<EFBFBD><EFBFBD><EFBFBD>";
if(strlen(costpasswd)!=16){
return "<EFBFBD><EFBFBD><EFBFBD>ܲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڡ<EFBFBD>";
}
if( strstr(costpasswd,"/")!=NULL || strstr(costpasswd,"*")!=NULL || strstr(costpasswd,"+")!=NULL || strstr(costpasswd,"-")!=NULL || strstr(costpasswd,";")!=NULL || strstr(costpasswd,":")!=NULL || strstr(costpasswd," ")!=NULL || strstr(costpasswd,"|")!=NULL || strstr(costpasswd,".")!=NULL || strstr(costpasswd,",")!=NULL || strstr(costpasswd,"'")!=NULL || strstr(costpasswd,"=")!=NULL || strstr(costpasswd,"`")!=NULL || strstr(costpasswd,"<")!=NULL || strstr(costpasswd,">")!=NULL || strstr(costpasswd,"!")!=NULL || strstr(costpasswd,"NULL")!=NULL){
return "<EFBFBD><EFBFBD><EFBFBD>ܷǷ<EFBFBD><EFBFBD><EFBFBD>";
}
static char token[256]="";
sprintf(sqlstr,"select `CostStr`, `check` from `OnlineBuy` where CostPasswd = BINARY'%s'", costpasswd);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
if(atoi(mysql_row[1]) == 1){
char *coststr = mysql_row[0];
sprintf(sqlstr,"update OnlineBuy set cdkey=BINARY'%s', CostTime=NOW(), `check`=0 where CostPasswd=BINARY'%s'", id, costpasswd);
if(!mysql_query(&mysql,sqlstr)){
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%s<><73><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>\n",costpasswd);
}
sprintf(token, "%c|%s", costpasswd[0], coststr);
return token;
}else{
return "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ù<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD>ʹ<EFBFBD>ã<EFBFBD>";
}
}else{
return "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><EFBFBD>";
}
}
return "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD>ϵ<EFBFBD><EFBFBD>";
}
void sasql_OnlineBuy_add( char *coststr, int type, int num )
{
char sqlstr[256];
char CostPasswd[32];
int i, j, k=0;
for(i=0;i<num;i++){
memset( CostPasswd, 0, sizeof( CostPasswd ) );
CostPasswd[0]='0' + type;
for(j=1;j<16;j++){
if(rand() % 2==0){
CostPasswd[j]=(rand() % 26) + 65;
}else{
CostPasswd[j]=(rand() % 10) + 48;
}
}
sprintf(sqlstr,"INSERT INTO OnlineBuy (CostPasswd, CostStr) VALUES (BINARY'%s', '%s')", CostPasswd, coststr);
if(!mysql_query(&mysql,sqlstr)){
mysql_result=mysql_store_result(&mysql);
mysql_free_result(mysql_result);
k++;
}else{
break;
}
}
if(type <= 0){
printf("<EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%d<><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n", k);
}else if(type == 1){
printf("<EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%d<><64><EFBFBD><EFBFBD>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n", k);
}else if(type >= 2){
printf("<EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%d<><64>ʯ<EFBFBD><CAAF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n", k);
}
return ;
}
#endif
#ifdef _PET_RESET
int sasql_resetpet_point(int petno){
char sqlstr[256];
sprintf(sqlstr,"select `Point` from `PetReset` where `PetNo`='%d'",petno);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
if(atoi(mysql_row[0]) >= 0){
return atoi(mysql_row[0]);
}else{
return -1;
}
}else{
mysql_free_result(mysql_result);
return -1;
}
}else{
return -1;
}
}
int sasql_resetbdpet_point(int petno){
char sqlstr[256];
sprintf(sqlstr,"select `BdPoint` from `PetReset` where `PetNo`='%d'",petno);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
if(atoi(mysql_row[0]) > 0){
return atoi(mysql_row[0]);
}else{
return -1;
}
}else{
mysql_free_result(mysql_result);
return -1;
}
}else{
return -1;
}
}
#endif
#ifdef _ZHIPIAO_SYSTEM
int sasql_zhipiao_insert(char *petno,char *cdkey,int point){
char sqlstr[256];
char ip[32];
if(strstr(cdkey,",")!=NULL) return -1;
//print("\npoint=%d\n",point);
sprintf(sqlstr,"select `IP` from `%s` where `%s`=BINARY'%s'",sqlconfig.sql_Table,sqlconfig.sql_NAME,cdkey);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
if(atoi(mysql_row[0]) >= 0){
sprintf(ip,mysql_row[0]);
}else{
return -1;
}
}else{
mysql_free_result(mysql_result);
return -1;
}
}
sprintf(sqlstr,"INSERT INTO ZhiPiao (PiaoNo, Point,Cdkey1,Date1,IP1) VALUES (BINARY'%s', %d,'%s',NOW(),'%s')", petno, point,cdkey,ip);
if(!mysql_query(&mysql,sqlstr)){
return 1;
}else{
return -1;
}
}
int sasql_zhipiao_query(char *piaono){
char sqlstr[256];
sprintf(sqlstr,"select `Point`,`check` from `ZhiPiao` where `PiaoNo`='%s'",piaono);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
if(atoi(mysql_row[1]) == 1){
return atoi(mysql_row[0]);
}else{
return 0;
}
}else{
mysql_free_result(mysql_result);
return -1;
}
}else{
return -1;
}
}
int sasql_zhipiao_update(char *cdkey,char *piaono,int checktype){
if(strstr(cdkey,",")!=NULL) return -1;
char sqlstr[256];
char ip[32];
sprintf(sqlstr,"select `IP` from `%s` where `%s`=BINARY'%s'",sqlconfig.sql_Table,sqlconfig.sql_NAME,cdkey);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
if(atoi(mysql_row[0]) >= 0){
sprintf(ip,mysql_row[0]);
}else{
return -1;
}
}else{
mysql_free_result(mysql_result);
return -1;
}
}
sprintf(sqlstr,"update ZhiPiao set Cdkey2=BINARY'%s', Date2=NOW(), `IP2`='%s', `check`=%d where PiaoNo=BINARY'%s'", cdkey,ip ,checktype,piaono);
if(!mysql_query(&mysql,sqlstr)){
return 1;
}else{
return -1;
}
}
#endif
#ifdef _FMRANK_POINT
int sasql_fm_query(void){
char sqlstr[256];
mysql_query(&mysql,"SET NAMES 'gbk'");
sprintf(sqlstr,"select * from `FmRank` ORDER by `Point` desc");
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
int i=0;
while((mysql_row=mysql_fetch_row(mysql_result)) && i<20){
fmrankindex[i]=atoi(mysql_row[0]);
sprintf(fmrankname[i],"%s",mysql_row[1]);
fmrankpoint[i]=atoi(mysql_row[2]);
i++;
}
mysql_free_result(mysql_result);
return i;
}else{
mysql_free_result(mysql_result);
return -1;
}
}else{
return -1;
}
}
int sasql_fmpoint_query(int fmindex){
char sqlstr[256];
mysql_query(&mysql,"SET NAMES 'gbk'");
sprintf(sqlstr,"select `Point` from `FmRank` where `Index`='%d'",fmindex);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
return atoi(mysql_row[0]);
}else{
mysql_free_result(mysql_result);
return -1;
}
}else{
return -1;
}
}
int sasql_fmno_query(int fmindex){
char sqlstr[256];
sprintf(sqlstr,"select `Index` from `FmRank` ORDER by `Point` desc");
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
int i=1;
while((mysql_row=mysql_fetch_row(mysql_result))){
if(atoi(mysql_row[0])==fmindex)
return i;
i++;
}
mysql_free_result(mysql_result);
return -1;
}else{
mysql_free_result(mysql_result);
return -1;
}
}else{
return -1;
}
}
int sasql_fmpoint_add(int fmindex,int point){
char sqlstr[256];
sprintf(sqlstr,"update `FmRank` set `Point`=%d where `Index`=%d",point,fmindex);
if(!mysql_query(&mysql,sqlstr)){
return 1;
}else{
return -1;
}
}
int sasql_fmindex_add(int fmindex,char *fmname,int point){
char sqlstr[256];
mysql_query(&mysql,"SET NAMES 'gbk'");
sprintf(sqlstr,"INSERT INTO `FmRank` (`Index`,`Name`,`Point`) VALUES (%d,'%s',%d)",fmindex,fmname,point);
if(!mysql_query(&mysql,sqlstr)){
return 1;
}else{
return -1;
}
}
int sasql_fmindex_del(int fmindex){
char sqlstr[256];
sprintf(sqlstr,"DELETE FROM `FmRank` where `Index`=%d",fmindex);
if(!mysql_query(&mysql,sqlstr)){
return 1;
}else{
return -1;
}
}
#endif
#ifdef _ITEM_RESET
int sasql_itemreset_query(int itemid){
char sqlstr[256];
sprintf(sqlstr,"select `ResetPoint` from `ItemReset` where `Id`='%d'",itemid);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
return atoi(mysql_row[0]);
}else{
mysql_free_result(mysql_result);
return -1;
}
}else{
return -1;
}
}
int sasql_itemdel_query(int itemid){
char sqlstr[256];
sprintf(sqlstr,"select `DelPoint` from `ItemReset` where `Id`='%d'",itemid);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
return atoi(mysql_row[0]);
}else{
mysql_free_result(mysql_result);
return -1;
}
}else{
return -1;
}
}
#endif
int sasql_cdkey_lock(char *cdkey,int locktype){
char sqlstr[256];
sprintf(sqlstr,"select * from `%s` where `%s`=BINARY'%s'",sqlconfig.sql_Table,sqlconfig.sql_NAME, cdkey);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
sprintf(sqlstr,"update `%s` set `Lock`=%d where `%s`=BINARY'%s'", sqlconfig.sql_Table,locktype,sqlconfig.sql_NAME, cdkey);
if(!mysql_query(&mysql,sqlstr)){
return 1;
}else{
return -1;
}
}else{
mysql_free_result(mysql_result);
}
}
return -1;
}
int sasql_ampoint( char *ID, int point, int flag )
{
char sqlstr[256];
sprintf(sqlstr,"select `AmPoint` from `%s` where `%s`=BINARY'%s'",sqlconfig.sql_Table,sqlconfig.sql_NAME,ID);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
if(flag==0){
return atoi(mysql_row[0]);
}
point+=atoi(mysql_row[0]);
sprintf(sqlstr,"update `%s` set `AmPoint`=%d where `%s`=BINARY'%s'", sqlconfig.sql_Table, point,sqlconfig.sql_NAME, ID);
if(!mysql_query(&mysql,sqlstr)){
return point;
}else{
return atoi(mysql_row[0]);
}
}else{
mysql_free_result(mysql_result);
}
}
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>%s<><73><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>\n",ID);
return -1;
}
#ifdef _RMB_SYSTEM
int sasql_rmbpoint( char *ID, int point, int flag )
{
char sqlstr[256];
sprintf(sqlstr,"select `RMBPOINT` from `%s` where `%s`=BINARY'%s'",sqlconfig.sql_Table,sqlconfig.sql_NAME,ID);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
if(flag==0){
return atoi(mysql_row[0]);
}
point+=atoi(mysql_row[0]);
sprintf(sqlstr,"update `%s` set `RMBPOINT`=%d where `%s`=BINARY'%s'", sqlconfig.sql_Table, point,sqlconfig.sql_NAME, ID);
if(!mysql_query(&mysql,sqlstr)){
return point;
}else{
return atoi(mysql_row[0]);
}
}else{
mysql_free_result(mysql_result);
}
}
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>%s<>ֽ<EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>\n",ID);
return -1;
}
#endif
int sasql_cdkey_online( char *cdkey )
{
char sqlstr[256];
sprintf(sqlstr,"select `Online` from `%s` where `%s`='%s'",sqlconfig.sql_Table,sqlconfig.sql_NAME,cdkey);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
return atoi(mysql_row[0]);
}else{
mysql_free_result(mysql_result);
return 0;
}
}
return 0;
}
int sasql_check_iponline( char *IP )
{
char sqlstr[256];
sprintf(sqlstr,"select * from `%s` where `IP`='%s'",sqlconfig.sql_Table,IP);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
mysql_free_result(mysql_result);
if(num_row>0){
return 1;
}else{
return 0;
}
}
return -1;
}
#ifdef _EV_NUM
char* sasql_ev_npcmsg( int npcno )
{
char sqlstr[256];
sprintf(sqlstr,"select * from `EvNpc` where `No`='%d'",npcno);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
return mysql_row[1];
}
mysql_free_result(mysql_result);
}
return "err";
}
char* sasql_ev_item( void )
{
char sqlstr[256];
sprintf(sqlstr,"select count(*) from `EvItem`");
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
int itemno;
itemno = RAND(1,atoi(mysql_row[0]));
sprintf(sqlstr,"select `Id`,`MixNum`,`MaxNum` from `EvItem` where `No`='%d'",itemno);
if(!mysql_query(&mysql,sqlstr)){
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
int itemnum = RAND(atoi(mysql_row[1]),atoi(mysql_row[2]));
sprintf(sqlstr,"%d|%d",atoi(mysql_row[0]),itemnum);
return sqlstr;
}
}
}
mysql_free_result(mysql_result);
}
return "err";
}
char* sasql_ev_pet( void )
{
char sqlstr[256];
sprintf(sqlstr,"select count(*) from `EvPet`");
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
int petno;
petno = RAND(1,atoi(mysql_row[0]));
sprintf(sqlstr,"select `PicId`,`Name`,`MixLv`,`MaxLv` from `EvItem` where `No`='%d'",petno);
if(!mysql_query(&mysql,sqlstr)){
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
sprintf(sqlstr,"%d|%s|%d|%d",atoi(mysql_row[0]),mysql_row[1],atoi(mysql_row[2]),atoi(mysql_row[3]));
return sqlstr;
}
}
}
mysql_free_result(mysql_result);
}
return "err";
}
#endif
char* sasql_rand_buf( void )
{
char sqlstr[256];
sprintf(sqlstr,"select count(*) from `RandBuf`");
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
int randno;
randno = RAND(1,atoi(mysql_row[0]));
sprintf(sqlstr,"select * from `RandBuf` LIMIT %d,%d",randno-1,randno);
if(!mysql_query(&mysql,sqlstr)){
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
sprintf(sqlstr,"%s|%s|%s|%s|%s|%s",mysql_row[0],mysql_row[1],mysql_row[2],mysql_row[3],mysql_row[4],mysql_row[5]);
return sqlstr;
}
}
}
mysql_free_result(mysql_result);
}
return "err";
}
int sasql_check_lockmac( char *mac)
{
char sqlstr[256];
sprintf(sqlstr,"select * from `LockMac` where `MAC`='%s'",mac);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
mysql_free_result(mysql_result);
if(num_row>0){
return 1;
}else{
return 0;
}
}
return -1;
}
int sasql_check_lockpcid( char *pcid)
{
char sqlstr[256];
sprintf(sqlstr,"select * from `LockMac` where `PcId`='%s'",pcid);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
mysql_free_result(mysql_result);
if(num_row>0){
return 1;
}else{
return 0;
}
}
return -1;
}
int sasql_check_lockip( char *IP , int type )
{
char sqlstr[256];
sprintf(sqlstr,"select * from `LockIP` where `IP`='%s' and `TYPE`=%d",IP,type);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
mysql_free_result(mysql_result);
if(num_row>0){
return 1;
}else{
return 0;
}
}
return -1;
}
int sasql_add_lockip(char *IP,int type,int online,int mode){
char sqlstr[256];
sprintf(sqlstr,"INSERT INTO `LockIP` (`IP`,`TYPE`,`Online`,`Mode`) VALUES ('%s',%d,%d,%d)",IP,type,online,mode);
if(!mysql_query(&mysql,sqlstr)){
return 1;
}else{
return -1;
}
}
int sasql_query_online_ip(char *IP){
char sqlstr[256];
sprintf(sqlstr,"select * from `OnlineIP` where `IP`='%s'",IP);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
mysql_free_result(mysql_result);
if(num_row>0){
return 1;
}else{
return 0;
}
}
return -1;
}
int sasql_online_ip(char *cdkey,char *IP){
char sqlstr[256];
sprintf(sqlstr,"select * from `OnlineIP` where `Name`='%s'",cdkey);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
mysql_free_result(mysql_result);
if(num_row>0){
sprintf(sqlstr,"update `OnlineIP` set `IP`='%s',`LoginTime`=NOW() where `Name`='%s'",IP,cdkey);
if(!mysql_query(&mysql,sqlstr)){
return 1;
}else{
return 0;
}
}else{
sprintf(sqlstr,"INSERT INTO `OnlineIP` (`Name`,`IP`,`LoginTime`) VALUES ('%s','%s',NOW())",cdkey,IP);
if(!mysql_query(&mysql,sqlstr)){
return 1;
}else{
return 0;
}
}
}
return -1;
}
int sasql_offlinenum( char *IP )
{
char sqlstr[256];
sprintf(sqlstr,"select count(*) from `%s` where `Online`=%d and `Offline`=1 and `IP`='%s'",sqlconfig.sql_Table,getServernumber(),IP);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
return atoi(mysql_row[0]);
}else{
mysql_free_result(mysql_result);
}
}
return 0;
}
int sasql_offlinejqmnum( char *cdkey )
{
char sqlstr[256];
char *pcid = NULL;
sprintf(sqlstr,"select `PcId` from `%s` where `%s`=BINARY'%s'",sqlconfig.sql_Table,sqlconfig.sql_NAME,cdkey);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
pcid = mysql_row[0];
if(pcid == NULL) return 0;
sprintf(sqlstr,"select count(*) from `%s` where `Online`=%d and `Offline`>0 and `PcId`='%s'",sqlconfig.sql_Table,getServernumber(),pcid);
if(!mysql_query(&mysql,sqlstr)){
num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
return atoi(mysql_row[0]);
}
}
}else{
mysql_free_result(mysql_result);
}
}
return 0;
}
char* sasql_ip( char *cdkey )
{
char sqlstr[256];
sprintf(sqlstr,"select `IP` from `%s` where `%s`=BINARY'%s'",sqlconfig.sql_Table,sqlconfig.sql_NAME,cdkey);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
return mysql_row[0];
}else{
mysql_free_result(mysql_result);
}
}
return "err";
}
char* sasql_query_jqm( char *cdkey )
{
char sqlstr[256];
sprintf(sqlstr,"select `PcId` from `%s` where `%s`=BINARY'%s'",sqlconfig.sql_Table,sqlconfig.sql_NAME,cdkey);
//print("\n sqlstr=%s",sqlstr);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
return mysql_row[0];
}else{
mysql_free_result(mysql_result);
}
}
return "err";
}
int sasql_setVipPoint( int charaindex, int point )
{
char sqlstr[256];
char *id = CHAR_getChar(charaindex, CHAR_CDKEY);
sprintf(sqlstr,"update %s set VipPoint=%d where %s=BINARY'%s'", sqlconfig.sql_Table, point, sqlconfig.sql_NAME, id);
if(!mysql_query(&mysql,sqlstr)){
//printf("<22>û<EFBFBD>%s<><73>ǰ<EFBFBD>ػر<D8BB>%d<><64>\n",id,point);
return point;
}
return -1;
}
int sasql_getVipPoint( int charaindex )
{
char sqlstr[256];
char *id = CHAR_getChar(charaindex, CHAR_CDKEY);
sprintf(sqlstr,"select VipPoint from `%s` where %s=BINARY'%s'", sqlconfig.sql_Table, sqlconfig.sql_NAME, id);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
// mysql_free_result(mysql_result);
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
return atoi(mysql_row[0]);
}
}
// printf("\n<><6E><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>\n");
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>[3]...");
// sasql_close();
// sasql_init();
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
return -1;
}
int sasql_setVipPointForCdkey( char *id, int point )
{
if(sasql_ckeckStrint(id) == FALSE){
printf("<EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD>%s\n",id);
return -1;
}
char sqlstr[256];
sprintf(sqlstr,"update %s set VipPoint=%d where %s=BINARY'%s'", sqlconfig.sql_Table, point, sqlconfig.sql_NAME, id);
if(!mysql_query(&mysql,sqlstr)){
//printf("<22>û<EFBFBD>%s<><73>ǰ<EFBFBD>ػر<D8BB>%d<><64>\n",id,point);
return point;
}
return -1;
}
int sasql_getVipPointForCdkey( char *id )
{
if(sasql_ckeckStrint(id) == FALSE){
printf("<EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD>%s\n",id);
return -1;
}
char sqlstr[256];
sprintf(sqlstr,"select VipPoint from `%s` where %s=BINARY'%s'", sqlconfig.sql_Table, sqlconfig.sql_NAME, id);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
return atoi(mysql_row[0]);
}
}
// printf("\n<><6E><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>\n");
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>[2]...");
// sasql_close();
// sasql_init();
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
return -1;
}
BOOL sasql_ckeckStrint( char *str )
{
int i;
for(i=0;i<strlen(str);i++){
if((str[i] < 'a' || str[i] > 'z') && (str[i] < 'A' || str[i] > 'Z') && (str[i] < '0' || str[i] > '9') && (str[i] != '.')){
return FALSE;
}
}
return TRUE;
}
#ifdef _CARD_PRODUCTION
/**
* <20><><EFBFBD>ɳ<EFBFBD>ֵ<EFBFBD><D6B5>
*/
void sasql_OnlineCost_add( int cost, int num)
{
char sqlstr[256];
char CostPasswd[32];
memset( CostPasswd, 0, sizeof( CostPasswd ) );
int i, j, k=0;
for(i=0;i<num;i++){
for(j=0;j<16;j++){
if(rand() % 2==0){
CostPasswd[j]=(rand() % 26) + 65;
}else{
CostPasswd[j]=(rand() % 10) + 48;
}
}
sprintf(sqlstr,"INSERT INTO OnlineCost (CostPasswd, CostVal) VALUES (BINARY'%s', %d)", CostPasswd, cost);
if(!mysql_query(&mysql,sqlstr)){
k++;
}else{
continue;
}
}
#ifdef _DEBUG
printf("<EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%d<><64><EFBFBD><EFBFBD>ֵ%d<>ij<EFBFBD>ֵ<EFBFBD><D6B5>\n", k, cost);
#endif
return ;
}
#endif
int sasql_jifenPoint( int charaindex )
{
//printf("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>\n");
char sqlstr[256];
char *id = CHAR_getChar(charaindex, CHAR_CDKEY);
sprintf(sqlstr,"select AmPoint from `%s` where %s=BINARY'%s'", sqlconfig.sql_Table, sqlconfig.sql_NAME, id);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
return atoi(mysql_row[0]);
}
}
printf("<EFBFBD><EFBFBD><EFBFBD>»<EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>\n");
return -1;
}
int sasql_setJfPoint( int charaindex, int point )
{
char sqlstr[256];
char *id = CHAR_getChar(charaindex, CHAR_CDKEY);
sprintf(sqlstr,"update %s set AmPoint=%d where %s=BINARY'%s'", sqlconfig.sql_Table, point, sqlconfig.sql_NAME, id);
if(!mysql_query(&mysql,sqlstr)){
//if(!sasql_mysql_query(sqlstr)){
return point;
}
return -1;
}
int sasql_xjPoint( int charaindex )
{
//printf("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>\n");
char sqlstr[256];
char *id = CHAR_getChar(charaindex, CHAR_CDKEY);
sprintf(sqlstr,"select RMBPOINT from `%s` where %s=BINARY'%s'", sqlconfig.sql_Table, sqlconfig.sql_NAME, id);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
return atoi(mysql_row[0]);
}
}
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>RMB<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>\n");
return -1;
}
int sasql_setxjPoint( int charaindex, int point )
{
char sqlstr[256];
char *id = CHAR_getChar(charaindex, CHAR_CDKEY);
sprintf(sqlstr,"update %s set RMBPOINT=%d where %s=BINARY'%s'", sqlconfig.sql_Table, point, sqlconfig.sql_NAME, id);
if(!mysql_query(&mysql,sqlstr)){
//if(!sasql_mysql_query(sqlstr)){
return point;
}
return -1;
}
struct youx{
int result;
int flg;
int errnono;
char* errstr;
int fieldCount;
int rowCount;
int rowAt;
}retlua;
#ifdef _CAX_LNS_MYSQLSUOXU
void sasql_LUASQLAdv(char* sqlstr,char* filepath,char* function,int npcindex ,int charaindex,char* msg,int flg)
{
char* data = sasql_LuaAdv_QueryR(sqlstr,flg);
NPC_Lua_SQLPushAdvCallBack(retlua.result,retlua.flg,retlua.errnono,retlua.errstr,retlua.fieldCount ,retlua.rowCount ,retlua.rowAt, data,filepath,function,npcindex,charaindex,msg );
}
char* sasql_LuaAdv_QueryR(char *sqlstr,int flg)
{
int rowAtt = 0;
static char buff[1024] = "";
snprintf(buff,1024, "");
buff[1023]='\0';
/*<2A><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>*/
retlua.result = 0;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ERROR
retlua.flg = flg;//<2F><><EFBFBD><EFBFBD>
retlua.errnono = 0;//MYSQL<51><4C><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
retlua.errstr = "";//MYSQL<51><4C><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
retlua.fieldCount = 0;//<2F><>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>
retlua.rowCount = 0;//<2F><>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
retlua.rowAt = 0;//<2F><>ǰ<EFBFBD><C7B0>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>
if (flg == 1 || flg == 2){
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (mysql_result == NULL)
{
retlua.result = -2;
}else if (mysql_eof(mysql_result))
{
retlua.result = -3;
}
if(num_row>0){
mysql_row = mysql_fetch_row(mysql_result);//<2F>Ӳ<EFBFBD>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡһ<C8A1><D2BB>
retlua.errnono = mysql_errno(&mysql);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
retlua.errstr = mysql_error(&mysql);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
retlua.fieldCount = mysql_field_count(&mysql);//<2F><><EFBFBD><EFBFBD>
retlua.rowCount = num_row;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
rowAtt++;
retlua.rowAt = rowAtt;//<2F><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>
if (flg == 1){
mysql_free_result(mysql_result);//<2F>ͷŽ<CDB7><C5BD><EFBFBD><EFBFBD><EFBFBD>
mysql_result = NULL;
rowAtt = 0;
}
int i;
for (i=0;i<retlua.fieldCount;i++)
{
snprintf(buff,sizeof(buff), "%s%s;",buff,(char*)mysql_row[i]);
}
if (num_row > 15) retlua.result = -1;
return buff;
}else {
retlua.errnono = mysql_errno(&mysql);
retlua.errstr = mysql_error(&mysql);
}
}
}else if (flg == 3){
int num_row=0;
if (mysql_result == NULL) {
retlua.result = -2;
return "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><EFBFBD>ͷš<EFBFBD>";
}
num_row=mysql_num_rows(mysql_result);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (mysql_eof(mysql_result))
{
retlua.result = -3;//<2F>Ѵﵽβ<EFB5BD>ˣ<EFBFBD><CBA3>ȸ<EFBFBD><C8B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѣ<EFBFBD><D1A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E6BDAB><EFBFBD>Զ<EFBFBD><D4B6>ͷš<CDB7>
}
if (num_row == rowAtt) {
mysql_free_result(mysql_result);//<2F>ͷŽ<CDB7><C5BD><EFBFBD><EFBFBD><EFBFBD>
mysql_result = NULL;
rowAtt = 0;
retlua.result = -3;
return "<EFBFBD>ѵ<EFBFBD><EFBFBD><EFBFBD>β<EFBFBD>У<EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD>ͷŽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
}
if(num_row>0){
mysql_row = mysql_fetch_row(mysql_result);//<2F>Ӳ<EFBFBD>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡһ<C8A1><D2BB>
retlua.errnono = mysql_errno(&mysql);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
retlua.errstr = mysql_error(&mysql);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
rowAtt++;
retlua.rowAt = rowAtt;//<2F><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>
retlua.fieldCount = mysql_field_count(&mysql);//<2F><><EFBFBD><EFBFBD>
retlua.rowCount = num_row;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (num_row > 15) retlua.result = -1;
int i;
for (i=0;i<retlua.fieldCount;i++)
{
snprintf(buff,sizeof(buff), "%s%s;",buff,(char*)mysql_row[i]);
}
return buff;
}else {
retlua.errnono = mysql_errno(&mysql);
retlua.errstr = mysql_error(&mysql);
}
}else if (flg == 4){
if (mysql_result == NULL) {
retlua.result = -2;
return "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><EFBFBD>ͷš<EFBFBD>";
}
mysql_free_result(mysql_result);//<2F>ͷŽ<CDB7><C5BD><EFBFBD><EFBFBD><EFBFBD>
mysql_result = NULL;
rowAtt = 0;
retlua.rowAt = rowAtt;//<2F><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>
retlua.errnono = mysql_errno(&mysql);
retlua.errstr = mysql_error(&mysql);
return "";
}
retlua.errnono = mysql_errno(&mysql);
retlua.errstr = mysql_error(&mysql);
return "";
}
void sasql_LUASQL(char* sqlstr,int row,char* filepath,char* function,int npcindex ,int charaindex,char* msg)
{
if(row == -1 )
{
mysql_query(&mysql,sqlstr);
}else{
NPC_Lua_SQLPushCallBack(sasql_Lua_QueryR(row,sqlstr),filepath,function,npcindex, charaindex,msg);
}
}
char* sasql_Lua_QueryR(int row,char *sqlstr)
{
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
mysql_free_result(mysql_result);
if(num_row>0){
mysql_row = mysql_fetch_row(mysql_result);
return (char*)mysql_row[row];
}
}else
return "SQL Query ERROR";
}
#endif
#ifdef _CAX_NEWMAC_LOGIN
char* sasql_query_mac( char *cdkey )
{
char sqlstr[256];
sprintf(sqlstr,"select `MAC` from `%s` where `%s`=BINARY'%s'",sqlconfig.sql_Table,sqlconfig.sql_NAME,cdkey);
//print("\n sqlstr=%s",sqlstr);
if(!mysql_query(&mysql,sqlstr)){
int num_row=0;
mysql_result=mysql_store_result(&mysql);
num_row=mysql_num_rows(mysql_result);
if(num_row>0){
mysql_row=mysql_fetch_row(mysql_result);
mysql_free_result(mysql_result);
return mysql_row[0];
}else{
mysql_free_result(mysql_result);
}
}
return "err";
}
#endif