⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 msgchat.cpp

📁 网络游戏通用架构, 这是基于boost和libevent写的一个程序
💻 CPP
字号:
#include "msgchat.h"

#include "serverscene.h"
#include "clientscene.h"
#include "myconsole.h"

int MsgChat::_type= 0;


MsgChat::MsgChat()
{
    _client= NULL;
}


MsgChat::MsgChat( const string& __msg )
: _msg(__msg)
{
}


MsgChat::~MsgChat()
{
}


int MsgChat::value_size(void)
{
    return static_cast<int>( _name.size()+1+_msg.size()+1 );
}


bool MsgChat::load( Buffer& __buffer )//return true for successed
{
    __buffer >> _name >> _msg;
    return true;
}


bool MsgChat::save( Buffer& __buffer ) const//return true for successed
{
    __buffer << _name << _msg;
    return true;
}


bool MsgChat::preProcess( Connection* __conn, Remote* __remote, World* __world, shared_ptr<Message>& __this )//return true to be queued
{
    _client= dynamic_cast<Client*>(__remote);
    _world= __world;
    return true;
}


bool MsgChat::process( shared_ptr<Message>& __this )//return true to be removed from the queue
{
    Scene* scene= & _world->getScene();
    ServerScene* server_scene= dynamic_cast<ServerScene*>( scene );
    if( server_scene ){
        //cout << _name << "\tsaid:\t" << _msg << endl;
        _name= _client->getName();
        list<Connection*>& connections= _world->getNetwork().getConnections();
        for( list<Connection*>::iterator itor= connections.begin(); itor!=connections.end(); ++itor ){
            (*itor)->send( __this );
        }
    }else{
        ClientScene* client_scene= static_cast<ClientScene*>( scene );
        client_scene->getConsole().getFrame() << _name << "\tsaid:\t" << _msg << "\n";
    }
    return true;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -