cocos2dx游戏任务系统开发之服务端数据库

cocos2dx游戏任务系统开发之服务端数据库,第1张

概述前面我给小伙伴们讲了任务系统客户端,服务端写了前搬部分的消息接受处理,现在我在借大家讲解一下当我在服务端这边接受到了客户端的消息,我要知道是不是满足了条件,现在你就要用到数据库了,不管是这样还有其他的比如像道具系统里面道具的查询,出售,人物上线的属性什么都是存到数据库的,这里数据库虽然存有大量的信息,但是在数据库里面做的逻辑 *** 作没多少数据库里面的 *** 作主要是增删改查存这些,其他基本都是在数据库之外 ***

前面我给小伙伴们讲了任务系统客户端,服务端写了前搬部分的消息接受处理,现在我在借大家讲解一下当我在服务端这边接受到了客户端的消息,我要知道是不是满足了条件,现在你就要用到数据库了,不管是这样还有其他的比如像道具系统里面道具的查询,出售,人物上线的属性什么都是存到数据库的,这里数据库虽然存有大量的信息,但是在数据库里面做的逻辑 *** 作没多少数据库里面的 *** 作主要是增删改查存这些,其他基本都是在数据库之外 *** 作,各位牛逼的大神都不要喷我这是个人学习来的,当然我才毕业没一年做起来有很多不完善的,我将在以后慢慢的完善改进,只求不喷。

#ifndef __BRUCE_DBPROXY_QUEST_HANDLER_header__#define __BRUCE_DBPROXY_QUEST_HANDLER_header__#include "typedef.hpp"#include <Network.hpp>#include "DBProxyApp.hpp"#include "MysqL.hpp"#include <DBProxyServer/Quest.hpp>#include "QuestCommon.hpp"DBPROXY_NS_BEGIN class QuestHandler { public: QuestHandler(); ~QuestHandler(); voID initialize(); private: // 正在进行时的任务; voID createtable(); // 创建完成任务以后储的任务表;AchIEve voID createAchIEvetable(); voID registerMessageHandler(); voID handleGameServerRequestQuestInfo(Message::Ptr &message); voID handleGameServerRequestQuestInfoCallBack(Result& result,SessionID sID,GS2DS_QuestsqlReq gQuestReqsql); //任务向关卡数据库查询提交的条件是否匹配; voID handleGametoMissonsqlQuestInfo(Message::Ptr &message); //取出来; voID handleGameServerRequestMissonQuestInfoCallBack(Result& result,GS2DS_QuestGetMissonCountInfoReq questGetMissonCountInfoReq); //删除当前数据表中所在的任务信息; voID handleGameDeleteQuestIDInof(Message::Ptr &message); //删除后的数据; voID handleDeleteDBProxyToGameQuestIDinfo(Result& result,GS2DS_QuesDeletesqlInfoReq mQuesDeletesqlInfoReq); //将删除的所有任务数据保存到下来; voID handleDeleteQuestSeave(Message::Ptr &message); //将删除的所有任务数据保存到下来; voID handleDeleteQuestIDinfo(Result& result,GS2DS_QuestDeltAndSeaveInfoReq sQuestDeltAndSeaveInfoReq); }; APP_NS_END #endif // !__BRUCE_DBPROXY_QUEST_HANDLER_header__
#include "QuestHandler.hpp"DBPROXY_NS_BEGINQuestHandler::QuestHandler(){}QuestHandler::~QuestHandler(){}voID QuestHandler::registerMessageHandler(){    //DEFREG_MESSAGE(ID_GS2DS_QuestReqsql,QuestHandler,handleGameServerRequestQuestInfo)    //接收Game过来的查询消息;    DEFREG_MESSAGE(ID_GS2DS_QuestsqlReq,handleGameServerRequestQuestInfo)    //接收任务向关卡数据库查请求提交的条件是否满足;    DEFREG_MESSAGE(ID_GS2DS_QuestGetMissonCountInfoReq,handleGametoMissonsqlQuestInfo)    //删除数据库中当前任务数据表示中的所在任务的信息;    DEFREG_MESSAGE(ID_GS2DS_QuesDeletesqlInfoReq,handleGameDeleteQuestIDInof)    //保存当前删除的信息;    DEFREG_MESSAGE(ID_GS2DS_QuestDeltAndSeaveInfoReq,handleDeleteQuestSeave)}voID QuestHandler::initialize(){    createtable();    createAchIEvetable();    registerMessageHandler();}//正在进行的任务表;voID QuestHandler::createtable(){    //正在进行的任务表;    static Colume Questtable[] =    {        { "ID","bigint","0" },//任务的ID;        { "type",//任务类型;         { "groups",//解锁等级;        { " count",//次数;    };    g_MysqL.executenors("CREATE table `chr_quest_rec` (`char_ID` int NOT NulL)");    g_MysqL.addColume(QUEST_INFO_table,Questtable,sizeof(Questtable) / sizeof(Colume));}voID QuestHandler::handleGameServerRequestQuestInfo(Message::Ptr &message){    GS2DS_QuestsqlReq questReqsql;    message->unpack(questReqsql);    char szsql[1024] = { 0 };    //从数据库中找出该玩家ID中的所任务信息;    sprintf_s(szsql,sizeof(szsql),"select ID,type,groups,count from chr_quest_rec where char_ID = %d AND ID = %d AND type = %d AND count = %d ",questReqsql.userID,questReqsql.nQuestID,questReqsql.nQuestType,questReqsql.nQuestCount);    query* pquery = g_connectionPool.createquery(szsql);    pquery->setCallBack(makeCallBack(&QuestHandler::handleGameServerRequestQuestInfoCallBack,this,message->getSessionID(),questReqsql));    g_connectionPool.pushquery(pquery);}voID QuestHandler::handleGameServerRequestQuestInfoCallBack(Result& result,SessionID sID,GS2DS_QuestsqlReq cquestReqsql){    if (result.errno())    {        BRUCE_LOG(BruCe::logger::Log_Error,"%d",cquestReqsql.userID);        BRUCE_LOG(BruCe::logger::Log_DeBUG,"%s:%d handleGameServerRequestQuestInfoCallBack erroe: %s",__file__,__liNE__,result.error().c_str());    }     DS2GS_QuestsqlAck qusetAcksql;    Row* pRow = nullptr;    for (Row* pRow = result.fetch(); pRow != NulL; pRow = result.fetch())    {        i32 sqlQuestInfo = 0;        *pRow >> sqlQuestInfo;        qusetAcksql.nQuestfistInfo.push_back(sqlQuestInfo);    }    // 将服务查询的数据发送给GameSever接收;    qusetAcksql.userID = cquestReqsql.userID;    qusetAcksql.seq = cquestReqsql.seq;    qusetAcksql.nQuestCount = cquestReqsql.nQuestCount;    qusetAcksql.nQuestType = cquestReqsql.nQuestType;    qusetAcksql.Result = 1;    Message::Ptr sendMsg(new Message());    sendMsg->pack(qusetAcksql);    g_sessionManager.send(sID,sendMsg);}    //任务向关卡数据库查询提交的条件是否匹配;voID QuestHandler::handleGametoMissonsqlQuestInfo(Message::Ptr &message){    GS2DS_QuestGetMissonCountInfoReq questGetMissonCountInfoReq;    message->unpack(questGetMissonCountInfoReq);    char szsql[1024] = { 0 };    //从数据库中找出该玩家ID中的所任务信息   如果当传进来的参数是你要选择的这个那么 (mission_count = mission_count);    //    sprintf_s(szsql,"select mission_count from mission_info where char_ID = %d AND mission_type = %d ",questGetMissonCountInfoReq.userID,questGetMissonCountInfoReq.mQuestType);    query* pquery = g_connectionPool.createquery(szsql);    pquery->setCallBack(makeCallBack(&QuestHandler::handleGameServerRequestMissonQuestInfoCallBack,questGetMissonCountInfoReq));    g_connectionPool.pushquery(pquery);}voID QuestHandler::handleGameServerRequestMissonQuestInfoCallBack(Result& result,GS2DS_QuestGetMissonCountInfoReq questGetMissonCountInfoReq){    if (result.errno())    {        BRUCE_LOG(BruCe::logger::Log_Error,questGetMissonCountInfoReq.mQuestType);        BRUCE_LOG(BruCe::logger::Log_DeBUG,"%s:%d handleGameServerRequestMissonQuestInfoCallBack erroe: %s",result.error().c_str());    }    DS2GS_QuestGetMissonCountInfoAck questGetMissonCountInfoAck;    for (Row* pRow = result.fetch(); pRow != NulL; pRow = result.fetch())     {        //*pRow >> questGetMissonCountInfoAck.mQuestType; *pRow >> questGetMissonCountInfoAck.mQuestCount; } // 将服务查询的数据发送给GameSever接收; questGetMissonCountInfoAck.userID = questGetMissonCountInfoReq.userID; questGetMissonCountInfoAck.seq = questGetMissonCountInfoReq.seq; questGetMissonCountInfoAck.mQuestID = questGetMissonCountInfoReq.mQuestID; questGetMissonCountInfoAck.Result = 1; Message::Ptr sendMsg(new Message()); sendMsg->pack(questGetMissonCountInfoAck); g_sessionManager.send(sID,sendMsg); } /***********创建第二张保存表提交完成的任务***************************************************/// 创建完成任务以后储的任务表;AchIEvevoID QuestHandler::createAchIEvetable(){    // 创建完成任务以后储存的任务表;    static Colume QuestAchIEvetable[] =    {        { "ID",//次数;    };    g_MysqL.executenors("CREATE table `chr_quest_achIEve` (`char_ID` int NOT NulL)");    g_MysqL.addColume(QUEST_ACHIEVE_table,QuestAchIEvetable,sizeof(QuestAchIEvetable) / sizeof(Colume));}//删除当前数据表中所在的任务信息;voID QuestHandler::handleGameDeleteQuestIDInof(Message::Ptr &message){    GS2DS_QuesDeletesqlInfoReq mQuesDeletesqlInfoReq;    message->unpack(mQuesDeletesqlInfoReq);    char szsql[1024] = { 0 };    //sprintf_s(szsql,"select chr_ques from mission_info where char_ID ",questGetMissonCountInfoReq.userID);    sprintf_s(szsql,"delete from chr_quest_rec where char_ID = %d AND ID = %d",mQuesDeletesqlInfoReq.userID,mQuesDeletesqlInfoReq.dQuestID);    query* pquery = g_connectionPool.createquery(szsql);    pquery->setCallBack(makeCallBack(&QuestHandler::handleDeleteDBProxyToGameQuestIDinfo,mQuesDeletesqlInfoReq));    g_connectionPool.pushquery(pquery);}//删除后的数据;voID QuestHandler::handleDeleteDBProxyToGameQuestIDinfo(Result& result,GS2DS_QuesDeletesqlInfoReq mQuesDeletesqlInfoReq){    if (result.errno())    {        BRUCE_LOG(BruCe::logger::Log_Error,mQuesDeletesqlInfoReq.dQuestID);        BRUCE_LOG(BruCe::logger::Log_DeBUG,"%s:%d handleDeleteDBProxyToGameQuestIDinfo erroe: %s",result.error().c_str());    }    DS2GS_QuesDeletesqlInfoAck mQuesDeletesqlInfoAck;    mQuesDeletesqlInfoAck.userID = mQuesDeletesqlInfoReq.userID;    mQuesDeletesqlInfoAck.seq = mQuesDeletesqlInfoReq.seq;    mQuesDeletesqlInfoAck.dQuestID = mQuesDeletesqlInfoReq.dQuestID;    Message::Ptr sendMsg(new Message());    sendMsg->pack(mQuesDeletesqlInfoAck);    g_sessionManager.send(sID,sendMsg);}//将删除的所有任务数据保存到下来;voID QuestHandler::handleDeleteQuestSeave(Message::Ptr &message){    GS2DS_QuestDeltAndSeaveInfoReq sQuestDeltAndSeaveInfoReq;    message->unpack(sQuestDeltAndSeaveInfoReq);    char szsql[1024] = { 0 };    sprintf_s(szsql,"insert into chr_quest_achIEve(char_ID,ID,count) value(%d,%d,%d)",sQuestDeltAndSeaveInfoReq.userID,sQuestDeltAndSeaveInfoReq.QuestSeaveDleID,sQuestDeltAndSeaveInfoReq.QuestSeaveDleType,sQuestDeltAndSeaveInfoReq.QuestSeaveDleGroups,sQuestDeltAndSeaveInfoReq.QuestSeaveDleCount);    query* pquery = g_connectionPool.createquery(szsql);    pquery->setCallBack(makeCallBack(&QuestHandler::handleDeleteQuestIDinfo,sQuestDeltAndSeaveInfoReq));    g_connectionPool.pushquery(pquery);}//将删除的所有任务数据保存下来;voID QuestHandler::handleDeleteQuestIDinfo(Result& result,GS2DS_QuestDeltAndSeaveInfoReq sQuestDeltAndSeaveInfoReq){    if (result.errno())    {        BRUCE_LOG(BruCe::logger::Log_Error,sQuestDeltAndSeaveInfoReq.userID);        BRUCE_LOG(BruCe::logger::Log_DeBUG,"%s:%d handleDeleteQuestIDinfo erroe: %s",result.error().c_str());    }    DS2GS_QuestDeltAndSeaveInfoAck sQuestDeltAndSeaveInfoAck;    sQuestDeltAndSeaveInfoAck.userID = sQuestDeltAndSeaveInfoReq.userID;    sQuestDeltAndSeaveInfoAck.seq = sQuestDeltAndSeaveInfoReq.seq;    sQuestDeltAndSeaveInfoAck.QuestSeaveDleID = sQuestDeltAndSeaveInfoReq.QuestSeaveDleID;    Message::Ptr sendMsg(new Message());    sendMsg->pack(sQuestDeltAndSeaveInfoAck);    g_sessionManager.send(sID,sendMsg);}APP_NS_END
总结

以上是内存溢出为你收集整理的cocos2dx游戏任务系统开发之服务端数据库全部内容,希望文章能够帮你解决cocos2dx游戏任务系统开发之服务端数据库所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1053486.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存