Move git root from Client/ to src/ to track all source code: - Client: Game client source (moved to Client/Client/) - Server: Game server source - GameTools: Development tools - CryptoSource: Encryption utilities - database: Database scripts - Script: Game scripts - rylCoder_16.02.2008_src: Legacy coder tools - GMFont, Game: Additional resources 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
308 lines
9.7 KiB
C++
308 lines
9.7 KiB
C++
#include "stdafx.h"
|
|
#include "ManageToolServerDispatch.h"
|
|
|
|
#include <tchar.h>
|
|
#include <Log/ServerLog.h>
|
|
#include <UserManage/ToolUserManageTable.h>
|
|
#include <Network/Session/Session.h>
|
|
#include <Network/Dispatch/SendManagePacket.h>
|
|
|
|
|
|
bool CManageToolServerDispatch::AuthUser(PktBase* lpPktBase)
|
|
{
|
|
unsigned char cError = 0;
|
|
|
|
ServerManage::UserCommand* lpUserCommand =
|
|
reinterpret_cast<ServerManage::UserCommand*>(lpPktBase);
|
|
|
|
ServerManage::UserInfo* lpUserInfo =
|
|
reinterpret_cast<ServerManage::UserInfo*>(lpUserCommand + 1);
|
|
|
|
if(!ServerManage::CheckUserPacketLength(lpPktBase, 1))
|
|
{
|
|
cError = ServerManage::INVALID_USER_PACKET_ERROR;
|
|
}
|
|
|
|
if(0 == cError)
|
|
{
|
|
m_UserInfo = *lpUserInfo;
|
|
m_UserInfo.dwIP = GetSession().GetRemoteAddr().get_addr_in().sin_addr.S_un.S_addr;
|
|
|
|
// 인증 성공시 LoginTable에 삽입된다.
|
|
cError = CToolUserManager::GetInstance().Authorize(*this, m_UserInfo);
|
|
if (cError != ServerManage::NO_USER_COMMAND_ERROR)
|
|
{
|
|
ERRLOG2(g_Log, "ID:%s/IP:%s/Authorize failed",
|
|
m_UserInfo.szID, GetSession().GetRemoteAddr().get_addr_string());
|
|
}
|
|
}
|
|
|
|
if(0 == cError)
|
|
{
|
|
DETLOG2(g_Log, "ID:%s/IP:%s/Authorize success",
|
|
m_UserInfo.szID, GetSession().GetRemoteAddr().get_addr_string());
|
|
|
|
// 다른 유저들에게 로그인 정보를 보낸다.
|
|
ServerManage::SendUserInfo(GetBufferFactory(), 0, &m_UserInfo, 1,
|
|
ServerManage::CMD::UserLogin, 0);
|
|
|
|
// 현재 관리자 정보를 준다.
|
|
ServerManage::SendUserInfo(GetBufferFactory(), 0,
|
|
&CToolUserManager::GetInstance().GetManageUser(), 1,
|
|
ServerManage::CMD::ManagerInfo, 0);
|
|
|
|
// 다른 유저들의 로그인 정보를 받는다.
|
|
CToolUserManager::GetInstance().SendAllLoginUserInfo(GetSession());
|
|
|
|
#pragma todo("서버 Setup을 준다")
|
|
}
|
|
|
|
ServerManage::SendUserInfo(GetBufferFactory(), &GetSession(), &m_UserInfo, 1,
|
|
ServerManage::CMD::AuthUser, cError);
|
|
|
|
return (0 == cError);
|
|
}
|
|
|
|
|
|
bool CManageToolServerDispatch::AddUser(PktBase* lpPktBase)
|
|
{
|
|
unsigned char cError = 0;
|
|
|
|
ServerManage::UserCommand* lpUserCommand =
|
|
reinterpret_cast<ServerManage::UserCommand*>(lpPktBase);
|
|
|
|
ServerManage::UserInfo* lpUserInfo =
|
|
reinterpret_cast<ServerManage::UserInfo*>(lpUserCommand + 1);
|
|
|
|
if(!ServerManage::CheckUserPacketLength(lpPktBase, 1))
|
|
{
|
|
cError = ServerManage::INVALID_USER_PACKET_ERROR;
|
|
}
|
|
|
|
if(0 == cError && !CToolUserManager::GetInstance().AddUser(*lpUserInfo))
|
|
{
|
|
ERRLOG3(g_Log, "ID:%s/IP:%s/Adduser failed (ID:%s)",
|
|
m_UserInfo.szID, GetSession().GetRemoteAddr().get_addr_string(), lpUserInfo->szID);
|
|
cError = ServerManage::ADD_USER_FAILED;
|
|
}
|
|
|
|
DETLOG3(g_Log, "ID:%s/IP:%s/Adduser success",
|
|
m_UserInfo.szID, GetSession().GetRemoteAddr().get_addr_string(), lpUserInfo->szID);
|
|
|
|
memset(lpUserInfo->szPassword, 0, ServerManage::UserInfo::PASS_LEN);
|
|
|
|
return ServerManage::SendUserInfo(GetBufferFactory(), &GetSession(), lpUserInfo, 1,
|
|
ServerManage::CMD::AddUser, cError);
|
|
}
|
|
|
|
|
|
bool CManageToolServerDispatch::DelUser(PktBase* lpPktBase)
|
|
{
|
|
unsigned char cError = 0;
|
|
|
|
ServerManage::UserCommand* lpUserCommand =
|
|
reinterpret_cast<ServerManage::UserCommand*>(lpPktBase);
|
|
|
|
ServerManage::UserInfo* lpUserInfo =
|
|
reinterpret_cast<ServerManage::UserInfo*>(lpUserCommand + 1);
|
|
|
|
if(!ServerManage::CheckUserPacketLength(lpPktBase, 1))
|
|
{
|
|
cError = ServerManage::INVALID_USER_PACKET_ERROR;
|
|
}
|
|
|
|
if(0 == cError && !CToolUserManager::GetInstance().DelUser(lpUserInfo->szID))
|
|
{
|
|
ERRLOG3(g_Log, "ID:%s/IP:%s/Delete user failed (ID:%s)",
|
|
m_UserInfo.szID, GetSession().GetRemoteAddr().get_addr_string(), lpUserInfo->szID);
|
|
cError = ServerManage::DELETE_USER_FAILED;
|
|
}
|
|
|
|
DETLOG3(g_Log, "ID:%s/IP:%s/Delete user success",
|
|
m_UserInfo.szID, GetSession().GetRemoteAddr().get_addr_string(), lpUserInfo->szID);
|
|
|
|
return ServerManage::SendUserInfo(GetBufferFactory(), &GetSession(), lpUserInfo, 1,
|
|
ServerManage::CMD::DelUser, cError);
|
|
}
|
|
|
|
|
|
bool CManageToolServerDispatch::ModUser(PktBase* lpPktBase)
|
|
{
|
|
unsigned char cError = 0;
|
|
|
|
ServerManage::UserCommand* lpUserCommand =
|
|
reinterpret_cast<ServerManage::UserCommand*>(lpPktBase);
|
|
|
|
ServerManage::UserInfo* lpUserInfo =
|
|
reinterpret_cast<ServerManage::UserInfo*>(lpUserCommand + 1);
|
|
|
|
if(!ServerManage::CheckUserPacketLength(lpPktBase, 1))
|
|
{
|
|
cError = ServerManage::INVALID_USER_PACKET_ERROR;
|
|
}
|
|
|
|
if(0 == cError && !CToolUserManager::GetInstance().ModifyUser(*lpUserInfo))
|
|
{
|
|
ERRLOG3(g_Log, "ID:%s/IP:%s/Modify user failed (ID:%s)",
|
|
m_UserInfo.szID, GetSession().GetRemoteAddr().get_addr_string(), lpUserInfo->szID);
|
|
cError = ServerManage::MODIFY_USER_FAILED;
|
|
}
|
|
|
|
DETLOG3(g_Log, "ID:%s/IP:%s/Modify user success",
|
|
m_UserInfo.szID, GetSession().GetRemoteAddr().get_addr_string(), lpUserInfo->szID);
|
|
|
|
memset(lpUserInfo->szPassword, 0, ServerManage::UserInfo::PASS_LEN);
|
|
|
|
return ServerManage::SendUserInfo(GetBufferFactory(), &GetSession(), lpUserInfo, 1,
|
|
ServerManage::CMD::ModUser, cError);
|
|
}
|
|
|
|
bool CManageToolServerDispatch::UserList(PktBase* lpPktBase)
|
|
{
|
|
unsigned char cError = 0;
|
|
|
|
ServerManage::UserCommand* lpUserCommand =
|
|
reinterpret_cast<ServerManage::UserCommand*>(lpPktBase);
|
|
|
|
if(!ServerManage::CheckUserPacketLength(lpPktBase, 0))
|
|
{
|
|
cError = ServerManage::INVALID_USER_PACKET_ERROR;
|
|
}
|
|
|
|
if(0 == cError && !CToolUserManager::GetInstance().SendAllUserInfo(GetSession()))
|
|
{
|
|
ERRLOG2(g_Log, "ID:%s/IP:%s/Send userlist failed",
|
|
m_UserInfo.szID, GetSession().GetRemoteAddr().get_addr_string());
|
|
|
|
cError = ServerManage::SEND_USER_LIST_FAILED;
|
|
}
|
|
|
|
DETLOG2(g_Log, "ID:%s/IP:%s/Send userlist success",
|
|
m_UserInfo.szID, GetSession().GetRemoteAddr().get_addr_string());
|
|
|
|
return ServerManage::SendUserInfo(GetBufferFactory(), &GetSession(), 0, 0,
|
|
ServerManage::CMD::UserList, cError);
|
|
}
|
|
|
|
|
|
bool CManageToolServerDispatch::RequestPromote(PktBase* lpPktBase)
|
|
{
|
|
unsigned char cError = 0;
|
|
|
|
ServerManage::UserCommand* lpUserCommand =
|
|
reinterpret_cast<ServerManage::UserCommand*>(lpPktBase);
|
|
|
|
ServerManage::UserInfo* lpUserInfo =
|
|
reinterpret_cast<ServerManage::UserInfo*>(lpUserCommand + 1);
|
|
|
|
if(!ServerManage::CheckUserPacketLength(lpPktBase, 1))
|
|
{
|
|
cError = ServerManage::INVALID_USER_PACKET_ERROR;
|
|
}
|
|
|
|
|
|
if(0 == cError)
|
|
{
|
|
const ServerManage::UserInfo& masterUser = CToolUserManager::GetInstance().GetManageUser();
|
|
|
|
if(0 == masterUser.szID[0] || m_UserInfo.usAdminLevel == CToolUserManager::MASTER)
|
|
{
|
|
// 현재 Promote유저가 있는지 살핀다. 없거나, Master면 바로 Promote를 하고 Broadcast를 한다.
|
|
CToolUserManager::GetInstance().Promote(m_UserInfo);
|
|
|
|
ServerManage::SendUserInfo(GetBufferFactory(), 0,
|
|
&m_UserInfo, 1, ServerManage::CMD::ManagerInfo, 0);
|
|
}
|
|
else if(m_UserInfo.usAdminLevel == CToolUserManager::GENERAL)
|
|
{
|
|
// 현재 Promote유저가 있고, 내가 General레벨이면, 정중히 요청을 한다.
|
|
CManageToolServerDispatch* lpToolUserDispatch =
|
|
CToolUserManager::GetInstance().GetManageUserDispatch();
|
|
|
|
ServerManage::UserInfo userInfo = m_UserInfo;
|
|
userInfo.usSubCommand = ServerManage::CMD::REQUEST_TAKEBACK_PROMOTE;
|
|
|
|
// 아직 연결되어 있으면 요청 패킷을 보냄.
|
|
if(0 == lpToolUserDispatch
|
|
|| !ServerManage::SendUserInfo(GetBufferFactory(),
|
|
&lpToolUserDispatch->GetSession(), &userInfo, 1,
|
|
ServerManage::CMD::RequestUserReaction, 0))
|
|
{
|
|
cError = ServerManage::PROMOTE_TAKEBACK_FAILED;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
cError = ServerManage::PROMOTE_USER_FAILED;
|
|
}
|
|
}
|
|
|
|
if(0 != cError)
|
|
{
|
|
ERRLOG3(g_Log, "ID:%s/IP:%s/Promote user failed (ID:%s)",
|
|
m_UserInfo.szID, GetSession().GetRemoteAddr().get_addr_string(), lpUserInfo->szID);
|
|
|
|
ServerManage::SendUserInfo(GetBufferFactory(), &GetSession(), 0, 0,
|
|
ServerManage::CMD::RequestPromote, cError);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
bool CManageToolServerDispatch::ProcessUserReaction(PktBase* lpPktBase)
|
|
{
|
|
unsigned char cError = 0;
|
|
|
|
ServerManage::UserCommand* lpUserCommand =
|
|
reinterpret_cast<ServerManage::UserCommand*>(lpPktBase);
|
|
|
|
ServerManage::UserInfo* lpUserInfo =
|
|
reinterpret_cast<ServerManage::UserInfo*>(lpUserCommand + 1);
|
|
|
|
if(!ServerManage::CheckUserPacketLength(lpPktBase, 1))
|
|
{
|
|
cError = ServerManage::INVALID_USER_PACKET_ERROR;
|
|
}
|
|
|
|
CManageToolServerDispatch* lpRequestDispatch = 0;
|
|
|
|
if(0 == cError)
|
|
{
|
|
switch(lpUserInfo->usSubCommand)
|
|
{
|
|
case ServerManage::CMD::ACK_TAKEBACK_PROMOTE:
|
|
|
|
// 처음 요청자를 찾아서 Promote 성공 패킷을 보낸다.
|
|
lpRequestDispatch = CToolUserManager::GetInstance().GetUserDispatch(lpUserInfo->szID);
|
|
if(0 != lpRequestDispatch)
|
|
{
|
|
ServerManage::UserInfo manager = lpRequestDispatch->GetUserInfo();
|
|
|
|
// Promote 처리.
|
|
CToolUserManager::GetInstance().Promote(manager);
|
|
|
|
// 누가 Manager인지 만천하에 알린다.
|
|
ServerManage::SendUserInfo(GetBufferFactory(), 0,
|
|
&manager, 1, ServerManage::CMD::ManagerInfo, 0);
|
|
|
|
// 본인에게 Ack.
|
|
ServerManage::SendUserInfo(GetBufferFactory(), &lpRequestDispatch->GetSession(),
|
|
&manager, 1, ServerManage::CMD::RequestPromote, 0);
|
|
}
|
|
break;
|
|
|
|
case ServerManage::CMD::NAK_TAKEBACK_PROMOTE:
|
|
// 처음 요청자를 찾아서 Promote 실패 패킷을 보낸다.
|
|
lpRequestDispatch = CToolUserManager::GetInstance().GetUserDispatch(lpUserInfo->szID);
|
|
if(0 != lpRequestDispatch)
|
|
{
|
|
ServerManage::SendUserInfo(GetBufferFactory(), &lpRequestDispatch->GetSession(),
|
|
&m_UserInfo, 1, ServerManage::CMD::RequestPromote, ServerManage::REJECTED_PROMOTE_USER);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
} |