GS deals with databases Link_stat stat=(Link_stat) rpkt.size;if(Stat = =link_stat::link_connected) {Gamechannel* PNEWGC =NewGamechannel (); PNEWGC->m_nchannelid = rpkt.channel_id;//Client Unique IdentityPnewgc->m_pdatalayer = M_spdatalayer.Get();//GC direct to clientPnewgc->m_pshare = This;//I know share is all players, all the maps, but the specific gameserver and share what relationship is not clearPNEWGC->M_PASYNDBC = This->m_spasyndbc.Get();//GC Access databasem_vecchannel[rpkt.channel_id]= PNEWGC;//put it in the player's channel.M_livemgr.add (rpkt.channel_id);}Else if(stat = = Link_stat::link_disconnected | | stat = =link_stat::link_connect_failed) {Gamechannel* PDISCONNECTGC =m_vecchannel[rpkt.channel_id]; if(PDISCONNECTGC) {//If you enter the map, you will be called Push_freequeue + hysteresis m_channels[channel_id] When you save the character information .Pdisconnectgc->ondisconnect ();//deal with player downline work, including map, feel this is just handling GS side of the//if the map is not in the offline, directly disconnected; Do not save role details, can be placed directly in the release queue if(!pdisconnectgc->m_pmap)//this needs to see the character of the line Ms How to send over, deal with what things, did not enter the map will not need to wait for MS to send data over and then GS save{AUTOFREEGC (PDISCONNECTGC);//release the GC, which requires no database return to release}} m_livemgr.remove (rpkt.channel_id);}BOOLGamechannel::onreceivedata (void* PData,intNlen) { if(! Basechannel::onreceivedata (PData, Nlen))//feel that the most basic functions are handled in BC { if(M_egamestate! =Egamestate_entermap)return false; M_pmap-Gs2msdata (Gs2ms_ turn client_cmd, M_nchannelid, PData, Nlen); } return true;}BOOLBasechannel::onreceivedata (void* Data,intLen) {Protocol Ptl= {0}; if(!ptl.from_buffer (data, Len))return false; Auto It= M_mappktanalysis.find (Ptl.cmd_type);//M_mappktanalysis is bound in the GC, and then the BC callback, this usage is really not familiar if(It = =m_mappktanalysis.end ())return false; returnIt->second (ptl.content, ptl.size);} See how it accesses the database.BOOLGamechannel::onlogin (void* PData,intNlen) { structUserInfo {intUserID;//_id in the corresponding database Charusername[ -];//User name Charuserpwd[ -];//User Password }; if(M_egamestate! =egamestate_onlyconnect)return false; UserInfo* Info = (userinfo*) PData; //M_fngetuserid a function,function is equivalent to a function pointer, the function address is stored in the code area, also has an address, the pointer to Asyndb, and then callback the pointer, is also canM_pasyndbc->getuserid (&m_fngetuserid, info->username);//so directly put a command to the database, in the callback, the server does not have to wait for the results, this is a relatively basic usage, just started to do not understand a few daysIncdbask (); M_puserinfo=NewShuihu::userinfo; strncpy (M_puserinfo->m_szuserpwd, info->userpwd, Max_name_len); return true;} GS and data deal with not much is gameserver open time to get props, gang information, the most important thing is that M_SPASYNDBC-Drive (); Driver Callback//In fact, the summary is that each GC has a database pointer, and then each binding a GC function, and then the database callback, of course, each class of object functions have address space, corresponding to this address space is not familiar
GS dealing with databases