code_app/sdk/webservice/WSServer.cpp

65 lines
1.1 KiB
C++

#include "WSServer.h"
#include "WSUser.h"
#include "base/HGInfo.h"
namespace ver_2
{
WSServer::WSServer(HGMsgPump msgPump, ManagerV2* manager)
: WebServer(msgPump)
{
m_manager = manager;
}
WSServer::~WSServer()
{
}
ManagerV2* WSServer::GetManger()
{
return m_manager;
}
void WSServer::Connect(const ConnectParam* param)
{
assert(NULL != param && this == param->svr);
if (!m_vectorUser.empty())
{
#if defined(HG_CMP_MSC)
closesocket(param->socket);
#else
close(param->socket);
#endif
return;
}
WebUser* user = new WSUser(this, m_currUserId, param->ip, param->port, param->socket);
user->Open();
++m_currUserId;
m_vectorUser.push_back(user);
}
void WSServer::Command(const WSCmdParam* param)
{
assert(NULL != param && this == param->svr);
int nIndex = GetUserIndex(param->usrId);
if (-1 != nIndex)
{
((WSUser*)m_vectorUser[nIndex])->HandleCmd(param);
}
}
void WSServer::Event(const WSEvtParam* param)
{
assert(NULL != param && this == param->svr);
int nIndex = GetUserIndex(param->usrId);
if (-1 != nIndex)
{
((WSUser*)m_vectorUser[nIndex])->HandleEvent(param);
}
}
}