📄 gobangdeal.cpp
字号:
void GobangDeal::TieRespond(TDBPEx *dbp,NODE_STRUCT recvnode){
char sqlbuf[1024]={0};
char *tempstr;
char *body;
NODE_STRUCT toothernode; //给房间里其他用户发送信息的节点
CString oppcountgroup="",countgroup="";
CString integral,gamelevel,Allcount,wincount;
CString equalcount,failcount;
short queuenum,otherqueuenum;
ULONG connectport,otherconnectport;
CString ipaddress,otheripaddress,seqnum;
short stepnum,orignstepnum;
CString func;
char chesscontent[227] = {0};
CString chesstemp,prestepstr="",prethistepstr="";
char prestep[50]={0};
CString userid,oppmind,roomid,tableid;
body = recvnode.body;
tempstr=split(body,SUBDIVISION);
userid = tempstr;
tempstr=split(body,SUBDIVISION);
stepnum = atoi(tempstr);
tempstr=split(body,SUBDIVISION);
oppmind = tempstr;
tempstr=split(body,SUBDIVISION);
roomid = tempstr;
tempstr=split(body,SUBDIVISION);
tableid = tempstr;
seqnum = roomid+tableid;
//更新用户的socket连接与用户状态
sprintf( sqlbuf, "update gobang_userinfo set status='01',queuenum=%d,ipaddress='%s',\
connectport=%d where userid='%s'",recvnode.queuenum,recvnode.clientip,\
recvnode.clientport,userid);
dbp->SQLExecDirect(sqlbuf,TRUE,TRUE);
//下面从数据库中取出已经的游戏步数
sprintf(sqlbuf,"select stepnum,Prefun from Gobang_gameinfo where seqid='%s'",seqnum);
dbp->SQLExecDirect(sqlbuf,FALSE);
if(dbp->SQLFetch() == PBL_Error_OK)
{
dbp->SQLGetDataSInt(1,orignstepnum);
dbp->SQLGetDataStr(2,func);
dbp->SQLFreeStmt();
if(stepnum == orignstepnum){ //该数据是重发数据,且对家还没采取对应的动作
return;
}else if(stepnum < orignstepnum){ //该数据是重发数据,且对家已采取对应的动作,不过玩家没收到
SalveDeal(dbp,recvnode,userid,roomid,tableid,orignstepnum,func);
}else{
//获取发起求和请求的用户信息
sprintf( sqlbuf, "select queuenum,ipaddress,connectport from Gobang_userinfo where roomid = '%s' \
and tableid = '%s' and userid <> '%s'",roomid,tableid,userid);
dbp->SQLExecDirect(sqlbuf,FALSE);
if(dbp->SQLFetch()==PBL_Error_OK){
dbp->SQLGetDataSInt(1,queuenum);
dbp->SQLGetDataStr(2,ipaddress);
dbp->SQLGetDataUInt(3,connectport);
dbp->SQLFreeStmt();
//判断是否同意和棋
if(strcmp(oppmind,"0")==0){ //同意和棋
CString seqid = roomid + tableid;
//通知房间里的其他用户该盘游戏结束
memset(&toothernode,0,sizeof toothernode);
strcpy(toothernode.err_code,"000");
strcpy(toothernode.service_id,"001");
strcpy(toothernode.operate_id,"519");
strcpy(toothernode.body,tableid);
sprintf(sqlbuf,"select queuenum, ipaddress,connectport from gobang_userinfo where roomid = '%s' \
and tableid <> '%s'",roomid,tableid);
dbp->SQLExecDirect(sqlbuf,false);
while (dbp->SQLFetch()==PBL_Error_OK) {
dbp->SQLGetDataSInt(1,otherqueuenum);
dbp->SQLGetDataStr(2,otheripaddress);
dbp->SQLGetDataUInt(3,otherconnectport);
toothernode.queuenum=otherqueuenum;
toothernode.clientport = otherconnectport;
strcpy(toothernode.clientip,otheripaddress);
//发送响应信息
if(recvnode.queuenum <= 0) { //玩家为机器人
svr_robot_queue->Insert(&toothernode);
}else{
svr_send_queue->Insert(&toothernode);
}
}
dbp->SQLFreeStmt();
//更新双方的统计数据
sprintf( sqlbuf,"update gobang_userinfo set allcount = allcount+1,equalcount = equalcount+1 \
where and tableid = '%s' and roomid = '%s'",
userid,tableid,roomid);
dbp->SQLExecDirect(sqlbuf,TRUE,TRUE);
//获取用户的统计
sprintf( sqlbuf,
"select a.integral,b.gamelevel,a.Allcount,a.wincount,a.equalcount,a.failcount \
from gobang_userinfo a, gobang_level b where b.integral =(select max(c.integral) \
from gobang_level c where a.integral >= c.integral) and a.userid ='%s'",userid);
dbp->SQLExecDirect(sqlbuf,FALSE);
if(dbp->SQLFetch() == PBL_Error_OK)
{
dbp->SQLGetDataStr(1,integral);
dbp->SQLGetDataStr(2,gamelevel);
dbp->SQLGetDataStr(3,Allcount);
dbp->SQLGetDataStr(4,wincount);
dbp->SQLGetDataStr(5,equalcount);
dbp->SQLGetDataStr(6,failcount);
countgroup =integral+"$"+gamelevel+"$"+Allcount+"$"+wincount+"$"+failcount+"$"+equalcount;
}
dbp->SQLFreeStmt();
//获取对手的统计
sprintf( sqlbuf,
"select a.integral,b.gamelevel,a.Allcount,a.wincount,a.equalcount,a.failcount \
from gobang_userinfo a, gobang_level b where b.integral =(select max(c.integral) \
from gobang_level c where a.integral >= c.integral) and a.userid <>'%s' \
and tableid='%s' and roomid='%s'",userid,tableid,roomid);
dbp->SQLExecDirect(sqlbuf,FALSE);
if(dbp->SQLFetch() == PBL_Error_OK)
{
dbp->SQLGetDataStr(1,integral);
dbp->SQLGetDataStr(2,gamelevel);
dbp->SQLGetDataStr(3,Allcount);
dbp->SQLGetDataStr(4,wincount);
dbp->SQLGetDataStr(5,equalcount);
dbp->SQLGetDataStr(6,failcount);
oppcountgroup =integral+"$"+gamelevel+"$"+Allcount+"$"+wincount+"$"+failcount+"$"+equalcount;
}
dbp->SQLFreeStmt();
//更新用户和对手的游戏状态
sprintf( sqlbuf, "update gobang_hallinfo set status = '01' where tableid = '%s' \
and roomid='%s'", tableid,roomid);
dbp->SQLExecDirect(sqlbuf,TRUE,TRUE);
//更新棋盘表信息
sprintf( sqlbuf, "update gobang_gameinfo set stepnum=%d,Prefun = '05' \
where seqid='%s'",stepnum,seqnum);
dbp->SQLExecDirect(sqlbuf,TRUE,TRUE);
//给用户反馈和棋后双方的统计数据
sprintf(recvnode.body,"%s;%s",countgroup,oppcountgroup);
strcpy(recvnode.operate_id,"535");
this->WriteLog("operateid:%s,%s",recvnode.clientip,recvnode.operate_id);
this->WriteLog("body:%s",recvnode.body);
if(recvnode.queuenum < 0) { //玩家为机器人
svr_robot_queue->Insert(&recvnode);
}else{
svr_send_queue->Insert(&recvnode);
}
//给发起求和请求的用户发数据
strcpy(recvnode.operate_id,"015");
recvnode.queuenum=queuenum;
recvnode.clientport = connectport;
strcpy(recvnode.clientip,ipaddress);
sprintf(recvnode.body,"0;%d;%s;%s",stepnum,oppcountgroup,countgroup);
this->WriteLog("operateid:%s,%s",recvnode.clientip,recvnode.operate_id);
this->WriteLog("body:%s",recvnode.body);
if(recvnode.queuenum < 0) { //玩家为机器人
svr_robot_queue->Insert(&recvnode);
}else{
svr_send_queue->Insert(&recvnode);
}
}else{//不同意求和
//更新棋盘表信息
sprintf( sqlbuf, "update gobang_gameinfo set stepnum=%d,Prefun = '06' \
where seqid='%s'",stepnum,seqnum);
dbp->SQLExecDirect(sqlbuf,TRUE,TRUE);
//给发起和棋请求的用户发数据
recvnode.queuenum=queuenum;
recvnode.clientport = connectport;
strcpy(recvnode.clientip,ipaddress);
sprintf(recvnode.body,"1;%d",stepnum);
strcpy(recvnode.operate_id,"015");
this->WriteLog("operateid:%s,%s",recvnode.clientip,recvnode.operate_id);
this->WriteLog("body:%s",recvnode.body);
if(recvnode.queuenum < 0) { //玩家为机器人
svr_robot_queue->Insert(&recvnode);
}else{
svr_send_queue->Insert(&recvnode);
}
}
}
}
}
}
//游戏中的用户求和操作请求
void GobangDeal::GamingTie(TDBPEx *dbp,NODE_STRUCT recvnode){
char sqlbuf[1024]={0};
char *tempstr;
char *body;
short queuenum;
ULONG connectport;
CString ipaddress,seqnum,func;
short stepnum,orignstepnum;
CString userid,roomid,tableid;
body = recvnode.body;
tempstr=split(body,SUBDIVISION);
userid = tempstr;
tempstr=split(body,SUBDIVISION);
stepnum = atoi(tempstr);
tempstr=split(body,SUBDIVISION);
roomid = tempstr;
tempstr=split(body,SUBDIVISION);
tableid = tempstr;
seqnum = roomid+tableid;
strcpy(recvnode.operate_id,"525");
//更新用户的socket连接与用户状态
sprintf( sqlbuf, "update gobang_userinfo set status='01',queuenum=%d,ipaddress='%s',\
connectport=%d where userid='%s'",recvnode.queuenum,recvnode.clientip,\
recvnode.clientport,userid);
dbp->SQLExecDirect(sqlbuf,TRUE,TRUE);
//下面从数据库中取出当前游戏的步数
sprintf(sqlbuf,"select stepnum,Prefun from Gobang_gameinfo where seqid='%s'",seqnum);
dbp->SQLExecDirect(sqlbuf,FALSE);
if(dbp->SQLFetch() == PBL_Error_OK)
{
dbp->SQLGetDataSInt(1,orignstepnum);
dbp->SQLGetDataStr(2,func);
}
dbp->SQLFreeStmt();
if(stepnum == orignstepnum){ //该数据是重发数据,且对家还没采取对应的动作
return;
}else if(stepnum < orignstepnum){ //该数据是重发数据,且对家已采取对应的动作,不过玩家没收到
SalveDeal(dbp,recvnode,userid,roomid,tableid,orignstepnum,func);
}
//更新棋盘表信息
sprintf( sqlbuf, "update gobang_gameinfo set stepnum=%d,Prefun = '04' where seqid='%s'",stepnum,seqnum);
dbp->SQLExecDirect(sqlbuf,TRUE,TRUE);
//获取对家连接信息
sprintf( sqlbuf, "select queuenum,ipaddress,connectport from Gobang_userinfo where roomid = '%s' \
and tableid = '%s' and userid <> '%s'",roomid,tableid,userid);
dbp->SQLExecDirect(sqlbuf,FALSE);
if(dbp->SQLFetch()==PBL_Error_OK){
dbp->SQLGetDataSInt(1,queuenum);
dbp->SQLGetDataStr(2,ipaddress);
dbp->SQLGetDataUInt(3,connectport);
recvnode.queuenum=queuenum;
recvnode.clientport = connectport;
strcpy(recvnode.clientip,ipaddress);
sprintf(recvnode.body,"%d",stepnum);
//给对家发送求和请求信息
this->WriteLog("operateid:%s,%s",recvnode.clientip,recvnode.operate_id);
this->WriteLog("body:%s",recvnode.body);
if(recvnode.queuenum < 0) { //玩家为机器人
svr_robot_queue->Insert(&recvnode);
}else{
svr_send_queue->Insert(&recvnode);
}
}
dbp->SQLFreeStmt();
}
//游戏中的用户认输操作请求
void GobangDeal::GamingSurrender(TDBPEx *dbp,NODE_STRUCT recvnode){
char sqlbuf[1024]={0};
char *tempstr;
char *body;
NODE_STRUCT toothernode; //给房间里其他用户发送信息的节点
short queuenum;
ULONG connectport;
CString ipaddress,seqnum,func;
short stepnum,orignstepnum;
CString userid,roomid,tableid;
CString oppcountgroup="",countgroup="";
CString integral,gamelevel,Allcount,wincount;
CString equalcount,failcount;
body = recvnode.body;
tempstr=split(body,SUBDIVISION);
userid = tempstr;
tempstr=split(body,SUBDIVISION);
stepnum = atoi(tempstr);
tempstr=split(body,SUBDIVISION);
roomid = tempstr;
tempstr=split(body,SUBDIVISION);
tableid = tempstr;
seqnum = roomid+tableid;
//更新用户的socket连接与用户状态
sprintf( sqlbuf, "update gobang_userinfo set status='01',queuenum=%d,ipaddress='%s',\
connectport=%d where userid='%s'",recvnode.queuenum,recvnode.clientip,\
recvnode.clientport,userid);
dbp->SQLExecDirect(sqlbuf,TRUE,TRUE);
//下面从数据库中取出当前游戏的步数
sprintf(sqlbuf,"select stepnum,Prefun from Gobang_gameinfo where seqid='%s'",seqnum);
dbp->SQLExecDirect(sqlbuf,FALSE);
if(dbp->SQLFetch() == PBL_Error_OK)
{
dbp->SQLGetDataSInt(1,orignstepnum);
dbp->SQLGetDataStr(2,func);
}
dbp->SQLFreeStmt();
if(stepnum == orignstepnum){ //该数据是重发数据,且对家还没采取对应的动作
return;
}else if(stepnum < orignstepnum){ //该数据是重发数据,且对家已采取对应的动作,不过玩家没收到
SalveDeal(dbp,recvnode,userid,roomid,tableid,orignstepnum,func);
}else{
//通知房间里的其他用户该盘游戏结束
memset(&toothernode,0,sizeof toothernode);
strcpy(toothernode.err_code,"000");
strcpy(toothernode.service_id,"001");
strcpy(toothernode.operate_id,"519");
strcpy(toothernode.body,tableid);
sprintf(sqlbuf,"select queuenum, ipaddress,connectport from gobang_userinfo where roomid = '%s' \
and tableid <> '%s'",roomid,tableid);
dbp->SQLExecDirect(sqlbuf,false);
while (dbp->SQLFetch()==PBL_Error_OK) {
dbp->SQLGetDataSInt(1,queuenum);
dbp->SQLGetDataStr(2,ipaddress);
dbp->SQLGetDataUInt(3,connectport);
toothernode.queuenum=queuenum;
toothernode.clientport = connectport;
strcpy(toothernode.clientip,ipaddress);
//发送响应信息
if(recvnode.queuenum <= 0) { //玩家为机器人
svr_robot_queue->Insert(&toothernode);
}else{
svr_send_queue->Insert(&toothernode);
}
}
dbp->SQLFreeStmt();
//更新用户的统计数据
sprintf( sqlbuf,"update gobang_userinfo set allcount = allcount+1,failcount = failcount+1,\
integral = integral-2 where userid = '%s'",userid);
dbp->SQLExecDirect(sqlbuf,TRUE,TRUE);
//更新对手的统计数据
sprintf( sqlbuf,"update gobang_userinfo set allcount = allcount+1,wincount = wincount+1,\
integral = integral+2 where userid <>'%s' and tableid = '%s' and roomid = '%s'",
userid,tableid,roomid);
dbp->SQLExecDirect(sqlbuf,TRUE,TRUE);
//获取用户的统计
sprintf( sqlbuf,
"select a.integral,b.gamelevel,a.Allcount,a.wincount,a.equalcount,a.failcount \
from gobang_userinfo a, gobang_level b where b.integral =(select max(c.integral) \
from gobang_level c where a.integral >= c.integral) and a.userid ='%s'",userid);
dbp->SQLExecDirect(sqlbuf,FALSE);
if(dbp->SQLFetch() == PBL_Error_OK)
{
dbp->SQLGetDataStr(1,integral);
dbp->SQLGetDataStr(2,gamelevel);
dbp->SQLGetDataStr(3,Allcount);
dbp->SQLGetDataStr(4,wincount);
d
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -