the player is offline and has been feeling the process a little complicated before.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 ();//some finishing touches to the downline//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) { //Pushfreequeue (PDISCONNECTGC); //m_vecchannel[rpkt.channel_id] = NULL;AUTOFREEGC (PDISCONNECTGC); }} m_livemgr.remove (rpkt.channel_id);//clear this position of Livemgr 0Take a step-by-step look at this processBOOLGamechannel::ondisconnect () {//M_isdisconnect = true;Onoffline (); return true;}voidGamechannel::onoffline () {Switch(m_egamestate) { CaseEgamestate_login://Login StatusCLEARLOGINRCD ();//Clear Login Status: Delete deleted role, delete online user Break; CaseEgamestate_entermap://go to map statusCLEARMAPRCD ();//from the map downline, this gets the back lookCLEARLOGINRCD ();//Clear Login Status Break; CaseEgamestate_inchangemap://... is transduction on the downline, is not the delay offline it? M_egamestate =Egamestate_delaydisconnect; CaseEgamestate_onlyconnect://not logged in, empty connection CaseEgamestate_disconnect://is offline return; default: Break; } m_egamestate= Egamestate_disconnect;//switch status to offline state}voidGAMESERVER::AUTOFREEGC (gamechannel*Pgamechannel) {M_vecchannel[pgamechannel->m_nchannelid] =NULL; //channel inside a m_udbgetaskrefcount, due to determine whether the database has returned, the database is slow to join the player offline you put this memory released, and so on when the database returned to visit the wild pointer if(Pgamechannel->isnodbask ())//without database access, you can safely delete pointers.{delete Pgamechannel;//Remove player PointerPgamechannel =nullptr; } Else{pushfreequeue (pgamechannel);//If there is still database access, put it in the release queue for deferred release }}voidGameserver::P ushfreequeue (gamechannel*GC) {Freechannel fch; Fch.m_pgamechannel=GC; Fch.m_utime=GetTickCount (); M_freequeue.push (FCH);}//So when did this queue get released? initialization of a timer in the main threadvoidGameserver::inittimer () {i_timerfactory* Ptimefactory =NEW (timerfactory); Setplug ("timerfactory", ptimefactory); M_freequeuetimer.reset (Ptimefactory-Createtimer ()); M_freequeuetimer->regtimer (Std::bind (&gameserver::freequeuetimer, This)); M_freequeuetimer->setinterval ( -* +);//(* +);M_freequeuetimer->start ();}//Before, there was an error in the function callback, which was the problem callback when the player has been offline, the channel has been deleted/** Scheme one: Do not release directly, delay 1 minutes, ensure that the database is no longer returned to release. (The database is too busy to deactivate) * Scenario two: Not directly released, see if the GC flag has no data request. */voidGameserver::freequeuetimer () {if(!m_freequeue.size ())return ; intnow =GetTickCount (); for(;;)//each time it is released or until there is no release. { if(!m_freequeue.size ())return ; Freechannel Tmpfreechannel=M_freequeue.front (); //if (now-tmpfreechannel.m_utime > *) if(Tmpfreechannel.m_pgamechannel->isnodbask ())//wait until the database is not accessed and then released{Delete Tmpfreechannel.m_pgamechannel; M_freequeue.pop (); } Else { Break; } }}
Player offline (GS section)