Ejemplo n.º 1
0
void CGameClient::SpawnPlayer( void )
{
	// run the entrance script
	if ( sv.m_bLoadgame )
	{	// loaded games are fully inited already
		// if this is the last client to be connected, unpause
		sv.SetPaused( false );
	}
	else
	{
		// set up the edict
		Assert( serverGameEnts );
		serverGameEnts->FreeContainingEntity( edict );
		InitializeEntityDLLFields( edict );
		
	}

	// restore default client entity and turn off replay mdoe
	m_nEntityIndex = m_nClientSlot+1;
	m_bIsInReplayMode = false;

	// set view entity
    SVC_SetView setView( m_nEntityIndex );
	SendNetMsg( setView );

	

	CBaseClient::SpawnPlayer();
}
Ejemplo n.º 2
0
void CGameClient::SendSound( SoundInfo_t &sound, bool isReliable )
{
	if ( IsFakeClient() && !IsHLTV() )
	{
		return; // dont send sound messages to bots
	}

	// don't send sound messages while client is replay mode
	if ( m_bIsInReplayMode )
	{
		return;
	}

	// reliable sounds are send as single messages
	if ( isReliable )
	{
		SVC_Sounds	sndmsg;
		char		buffer[32];

		m_nSoundSequence = ( m_nSoundSequence + 1 ) & SOUND_SEQNUMBER_MASK;	// increase own sound sequence counter
		sound.nSequenceNumber = 0; // don't transmit nSequenceNumber for reliable sounds

		sndmsg.m_DataOut.StartWriting(buffer, sizeof(buffer) );
		sndmsg.m_nNumSounds = 1;
		sndmsg.m_bReliableSound = true;
				
		SoundInfo_t	defaultSound; defaultSound.SetDefault();

		sound.WriteDelta( &defaultSound, sndmsg.m_DataOut );

		// send reliable sound as single message
		SendNetMsg( sndmsg, true );
		return;
	}

	sound.nSequenceNumber = m_nSoundSequence;

	m_Sounds.AddToTail( sound );	// queue sounds until snapshot is send
}
Ejemplo n.º 3
0
void GLoginUser::OnNetMsg(const void* data, uint32_t size)
{
    switch (_loginState)
    {
    case kWaitCheckVersion:
        {
            G_CHECKMSG_PARA(data, size, GMsgClient2LoginCheckVersion, kParamCheckVersion);

            const GMsgClient2LoginCheckVersion* msg = (GMsgClient2LoginCheckVersion*)data;
            GMsgLogin2ClientCheckVersion reply;

            if (msg->version < g_version)
            {
                reply.result = GMsgLogin2ClientCheckVersion::kNeedUpdate;
            }
            else
            {
                reply.result = GMsgLogin2ClientCheckVersion::kOk;
                _loginState = kWaitRegOrAuthAccount;
            }

            SendNetMsg(&reply, sizeof(reply));
        }
        break;

    case kWaitRegOrAuthAccount:
        {
            G_CHECKMSG_PARA2(data, size, GMsgClient2LoginRegAccount, kParamRegAccount, GMsgClient2LoginAuthAccount, kParamAuthAccount);
            const GMsgNull* msgNull = (GMsgNull*)data;
            
            if (GMsgClient2LoginRegAccount::kParamRegAccount == msgNull->para)
            {
                const GMsgClient2LoginRegAccount* msg = (GMsgClient2LoginRegAccount*)data;
                GMsgLogin2ClientRegAccount reply;
                reply.result = GAccountService::GetSingleton().RegAccount(msg->account, msg->password);
                SendNetMsg(&reply, sizeof(reply));
            }

            if (GMsgLogin2ClientAuthAccount::kParamAuthAccount == msgNull->para)
            {
                const GMsgClient2LoginAuthAccount* msg = (GMsgClient2LoginAuthAccount*)data;

                const GAccountService::Account* acc = GAccountService::GetSingleton().GetAccount(msg->account);
                if (nullptr == acc)
                {
                    GMsgLogin2ClientAuthAccount reply;
                    reply.result = GMsgLogin2ClientAuthAccount::kAccountNotExist;
                    SendNetMsg(&reply, sizeof(reply));
                }
                else if (strcmp(msg->password, acc->password) != 0)
                {
                    GMsgLogin2ClientAuthAccount reply;
                    reply.result = GMsgLogin2ClientAuthAccount::kPasswordError;
                    SendNetMsg(&reply, sizeof(reply));
                }
                else
                {
                    LOG_INFO("Connection[%u] checkacount success[%s:%s]!", _connID, msg->account, msg->password);
                    
                    const GZoneService::ServerListT& srvs = GZoneService::GetSingleton().GetServerList();
                    G_NETMSG_BEG(GMsgLogin2ClientServerList, reply);
                    for (GZoneService::ServerListT::const_iterator iter = srvs.begin();
                        iter != srvs.end();
                        ++iter)
                    {
                        const GZoneService::Server& srv = iter->second;
                        if (acc->gmlevel < srv.gmlevel)
                            continue;

                        reply->data[reply->num].serverid = srv.serverid;
                        reply->data[reply->num].zoneidx = srv.zoneidx;
                        KStrCpy(reply->data[reply->num].name, srv.name);
                        reply->data[reply->num].showtype = srv.showtype;
                        reply->data[reply->num].gametype = srv.gametype;
                        reply->data[reply->num].serverstatus = srv.serverstatus;

                        ++reply->num;
                    }
                    G_NETMSG_END(reply);
                    SendNetMsg(reply, reply->Size());

                    _gmlevel = acc->gmlevel;
                    _loginState = kWaitSelectServer;
                }
            }
        }
        break;

    case kWaitSelectServer:
        {
            G_CHECKMSG_PARA(data, size, GMsgClient2LoginSelectServer, kParamSelectServer);
            const GMsgClient2LoginSelectServer* msg = (GMsgClient2LoginSelectServer*)data;
            GMsgLogin2ClientSelectServer reply;

            const GZoneService::Server* srv = GZoneService::GetSingleton().GetServer(msg->serverid);
            if (nullptr == srv)
            {
                reply.result = GMsgLogin2ClientSelectServer::kServerIDNotExist;
            }
            else if (_gmlevel < srv->gmlevel)
            {
                reply.result = GMsgLogin2ClientSelectServer::kGMLevelTooLow;
            }
            else
            {
                _loginState = kWaitDisconnect;

                LOG_INFO("Connection[%u] select server[%s %s:%u]", _connID, srv->name, srv->ip, srv->port);

                reply.result = GMsgLogin2ClientSelectServer::kOk;
                KStrCpy(reply.ip, srv->ip);
                reply.port = srv->port;
                reply.loginid = 12345678;
            }

            SendNetMsg(&reply, sizeof(reply));
        }
        break;

    case kWaitDisconnect:
        {
            G_CHECKMSG_PARA(data, size, GMsgClient2LoginSelectServer, kParamDisconnect);
            Close();
        }
        break;

    default:
        Close();
        break;
    }
}