Mangos源码分析
------realmd登陆服务器
Realmd主程序
/// Launch the realm server
int main(int argc, char **argv)
{
//输入参数分析,”-c”指定配置文件
//sConfig.SetSource(cfg_file),加载指定的配置文件
//进行版本号检查
///- Initialise the database connection
std::string dbstring;
if(!StartDB(dbstring))//初始化DB
///- Get the list of realms for the server
m_realmList.Initialize(sConfig.GetIntDefault("RealmsStateUpdateDelay", 20));//登陆服务器列表
SocketHandler h;
ListenSocket<AuthSocket> authListenSocket(h);
if ( authListenSocket.Bind(rmport))//绑定登陆服务器的端口
{
sLog.outError( "MaNGOS realmd can not bind to port %d", rmport );
return 1;
}
h.Add(&authListenSocket);
//进行一些参数设置
while (!stopEvent) //服务器主循环
{
h.Select(0, 100000);//对监听的SOCKET做select操作
if( (++loopCounter) == numLoops )
{
loopCounter = 0;
sLog.outDetail("Ping MySQL to keep connection alive");
delete dbRealmServer.Query("SELECT 1 FROM `realmlist` LIMIT 1");
}
}
//。。。。。。。。。。
return 0;
}//end main
int SocketHandler::Select(long sec,long usec)
{
struct timeval tv;
tv.tv_sec = sec;
tv.tv_usec = usec;
return Select(&tv);
}
int SocketHandler::Select(struct timeval *tsel)
{
//n = select( (int)(m_maxsock + 1),&rfds,&wfds,&efds,tsel);
// if (n > 0)
//p -> OnRead() or p -> OnWrite();
}
/// Read the packet from the client
void AuthSocket::OnRead()
{
///- Read the packet
TcpSocket::OnRead();
//从table表中查找对应的CMD,找到后调用对应的handler函数
}
const AuthHandler table[] =
{
{ AUTH_LOGON_CHALLENGE, STATUS_CONNECTED, &AuthSocket::_HandleLogonChallenge},
{ AUTH_LOGON_PROOF, STATUS_CONNECTED, &AuthSocket::_HandleLogonProof },
{ REALM_LIST, STATUS_AUTHED, &AuthSocket::_HandleRealmList },
{ XFER_ACCEPT, STATUS_CONNECTED, &AuthSocket::_HandleXferAccept },
{ XFER_RESUME, STATUS_CONNECTED, &AuthSocket::_HandleXferResume },
{ XFER_CANCEL, STATUS_CONNECTED, &AuthSocket::_HandleXferCancel }
};
typedef struct AuthHandler
{
eAuthCmd cmd;
uint32 status;
bool (AuthSocket::*handler)(void);
}AuthHandler;
/// Logon Challenge command handler
bool AuthSocket::_HandleLogonChallenge()
{
//从realmd.account表中找到用户,检查IP是否锁定;
//从realmd.account表中得到密码,使用SRP6计算得到v,s的值;//并将v,s的值更新到account表中。
//向客户端发送响应包
return true;
}