sphandler.cpp

来自「国外网游源码....除工具源码缺少之外,其余程序都全...至于,什么游戏,因为国」· C++ 代码 · 共 838 行 · 第 1/2 页

CPP
838
字号
#include "stdafx.h"
#include "MasterServer.h"
#include "spHandler.h"
#include "msgHandler.h"
#include "manager.h"
#include "local.h"
#include "user.h"


extern char use_type[];

bool spsel_server_info(char *svr_name, char *svr_group)
{
	SPINFO *sp = g_cMasterServer.GetSpObj();
	if(!sp)
	{
		_printf("**********************************exception************************************\n");
		_log("LOCAL'%s:%s' MempoolError[g_cMasterServer::GetSpObj() == NULL] spsel_server_info()", svr_name, svr_group);
		return false;
	}

	strcpy(sp->SAGetServerInfo.id, svr_name);
	strcpy(sp->SAGetServerInfo.group, svr_group);

	sp->index = 0;
	sp->sp_index = SPSEL_SERVER_INFO;
	g_cMasterServer.SetSp(sp);

	return true;
}

void spset_server_info(CADORecordset *pRec)
{
	pRec->GetData(0, g_cMasterServer.m_cLocalConn.account, g_cMasterServer.m_cLocalConn.type, g_cMasterServer.m_cLocalConn.name, g_cMasterServer.m_cLocalConn.mode, NULL);

	g_cMasterServer.RegiLocal();
}

bool spsel_server_index(char *svr_name, char *svr_group)
{
	SPINFO *sp = g_cMasterServer.GetSpObj();
	if(!sp)
	{
		_printf("**********************************exception************************************\n");
		_log("LOCAL'%s:%s' MempoolError[g_cMasterServer::GetSpObj() == NULL] spsel_server_index()", svr_name, svr_group);
		return false;
	}

	char *svr_addr, *svr_domain;
	net_info(svr_addr, svr_domain);

	strcpy(sp->MCGetServerIndex.remote_ip, svr_addr);
	strcpy(sp->MCGetServerIndex.id, svr_name);
	strcpy(sp->MCGetServerIndex.group, svr_group);

	sp->index = 0;
	sp->sp_index = SPSEL_SERVER_INDEX;
	g_cMasterServer.SetSp(sp);

	return true;
}

void spset_server_index(CADORecordset *pRec)
{
	pRec->GetData(0, g_cMasterServer.m_cLocalConn.account, NULL);
}

bool spsel_master_author()
{
	SPINFO *sp = g_cMasterServer.GetSpObj();
	if(!sp)
	{
		_printf("**********************************exception************************************\n");
		_log("MASTER MempoolError[g_cMasterServer::GetSpObj() == NULL] spsel_master_author()");
		return false;
	}

	char *svr_addr, *svr_domain;
	net_info(svr_addr, svr_domain);

	sp->SAGetServerAuthor.account = g_cMasterServer.m_cConfig.sys_account;
	sp->SAGetServerAuthor.port = g_cMasterServer.m_cConfig.sys_port_tcp;
	strcpy(sp->SAGetServerAuthor.remote_ip, svr_addr);

	sp->index = 0;
	sp->sp_index = SPSEL_MASTER_AUTHOR;
	g_cMasterServer.SetSp(sp);
	return true;
}

void spset_master_author(CADORecordset *pRec)
{
	UINT64 account;
	BYTE auth_size;
	char auth_index[MAX_AUTHSIZE];
	char auth_code[MAX_AUTHSIZE];
	char *ptr_index = auth_index;
	char *ptr_code = auth_code;

	pRec->GetData(1, &account, &auth_size, auth_index, auth_code, NULL);

	if(account != g_cMasterServer.m_cConfig.sys_account)
	{
		_printf("**********************************exception************************************\n");
		_log("MASTER AccountError[account != %I64d] spset_master_author() > 罐篮 拌沥锅龋[%I64d]", g_cMasterServer.m_cConfig.sys_account, account);
		return;
	}

	SAFE_DELETE_ARRAY(g_cMasterServer.m_cConfig.sys_auth_index);
	SAFE_DELETE_ARRAY(g_cMasterServer.m_cConfig.sys_auth_code);

	g_cMasterServer.m_cConfig.sys_auth_index = new BYTE[auth_size];
	g_cMasterServer.m_cConfig.sys_auth_code = new BYTE[auth_size];
	g_cMasterServer.m_cConfig.sys_auth_size = auth_size;
	g_cMasterServer.m_cConfig.sys_auth_cnt = 0;

	while(1)
	{
		g_cMasterServer.m_cConfig.sys_auth_index[g_cMasterServer.m_cConfig.sys_auth_cnt] = atoi(ptr_index);
		g_cMasterServer.m_cConfig.sys_auth_code[g_cMasterServer.m_cConfig.sys_auth_cnt] = atoi(ptr_code);

		++g_cMasterServer.m_cConfig.sys_auth_cnt;

		ptr_index = strstr(ptr_index, " ");
		ptr_code = strstr(ptr_code, " ");

		if(!ptr_index || !ptr_code)
			break;

		++ptr_index;
		++ptr_code;
	}

	g_cMasterServer.GetManager()->SetButtonWaiting();
}

bool spsel_server_author(int id)
{
	SPINFO *sp = g_cMasterServer.GetSpObj();
	if(!sp)
	{
		_printf("**********************************exception************************************\n");
		_log("LOCAL%d MempoolError[g_cMasterServer::GetSpObj() == NULL] spsel_server_author()", id);
		return false;
	}

	CLocal *pLocal = (CLocal *)g_cMasterServer.GetClient(id);
	if(!pLocal)
	{
		_printf("**********************************exception************************************\n");
		_log("LOCAL%d IndexError[local == NULL] spsel_server_author()", id);
		return false;
	}
	if(pLocal->m_nState != CClient::STATE_CONNECT)
	{
		_printf("**********************************exception************************************\n");
		_log("LOCAL%d StateError[state != STATE_CONNECT] spsel_server_author() > 泅犁 辑滚惑怕[%s]", pLocal->m_nIndex, pLocal->GetStateLog());
		return false;
	}

	IN_ADDR in_addr;
	in_addr.s_addr = pLocal->m_dwRemoteIP;

	sp->SAGetServerAuthor.account = pLocal->m_nAccount;
	sp->SAGetServerAuthor.port = pLocal->m_wPort;
	strcpy(sp->SAGetServerAuthor.remote_ip, inet_ntoa(in_addr));

	sp->index = pLocal->m_nIndex;
	sp->sp_index = SPSEL_SERVER_AUTHOR;
	g_cMasterServer.SetSp(sp);
	return true;
}

void spset_server_author(CADORecordset *pRec, int id)
{
	UINT64 account;
	BYTE auth_size;
	char auth_index[MAX_AUTHSIZE];
	char auth_code[MAX_AUTHSIZE];
	char *ptr_index = auth_index;
	char *ptr_code = auth_code;

	pRec->GetData(1, &account, &auth_size, auth_index, auth_code, NULL);

	CLocal *pLocal = (CLocal *)g_cMasterServer.GetClient(id);
	if(!pLocal)
	{
		_printf("**********************************exception************************************\n");
		_log("LOCAL%d IndexError[local == NULL] spset_server_author()", id);
		return;
	}
	if(pLocal->m_nState != CClient::STATE_CONNECT)
	{
		_printf("**********************************exception************************************\n");
		_log("LOCAL%d StateError[state != STATE_CONNECT] spset_server_author() > 泅犁 辑滚惑怕[%s]", pLocal->m_nIndex, pLocal->GetStateLog());
		return;
	}
	if(account != pLocal->m_nAccount)
	{
		_printf("**********************************exception************************************\n");
		_log("LOCAL%d IndexError[account != %I64d] spset_server_author() > 罐篮 拌沥[%I64d]", pLocal->m_nIndex, pLocal->m_nAccount, account);
		return;
	}

	SAFE_DELETE_ARRAY(pLocal->m_pAuthIndex);
	SAFE_DELETE_ARRAY(pLocal->m_pAuthCode);

	pLocal->m_pAuthIndex = new BYTE[auth_size];
	pLocal->m_pAuthCode = new BYTE[auth_size];
	pLocal->m_nAuthSize = auth_size;
	pLocal->m_nAuthCnt = 0;

	while(1)
	{
		pLocal->m_pAuthIndex[pLocal->m_nAuthCnt] = atoi(ptr_index);
		pLocal->m_pAuthCode[pLocal->m_nAuthCnt] = atoi(ptr_code);

		++pLocal->m_nAuthCnt;

		ptr_index = strstr(ptr_index, " ");
		ptr_code = strstr(ptr_code, " ");

		if(!ptr_index || !ptr_code)
			break;

		++ptr_index;
		++ptr_code;
	}

	void *ioc = net_message(M_MASTERSERVER, S_VERIFY, 0);
	if(ioc)
	{
		net_packet(ioc, &pLocal->m_nAuthSize, 1);
		net_packet(ioc, &pLocal->m_nAuthCnt, 1);
		net_packet(ioc, pLocal->m_pAuthIndex, pLocal->m_nAuthCnt);
		net_packet(ioc, pLocal->m_pAuthCode, pLocal->m_nAuthCnt);

		if(!net_send(id, ioc))
			net_disconnect(id, false);
	}
}

bool spupd_server_login(int id)
{
	SPINFO *sp = g_cMasterServer.GetSpObj();
	if(!sp)
	{
		_printf("**********************************exception************************************\n");
		_log("PC%d MempoolError[g_cMasterServer::GetSpObj() == NULL] spupd_server_login()", id);
		return false;
	}

	CLocal *pLocal = (CLocal *)g_cMasterServer.GetClient(id);
	if(!pLocal)
	{
		_printf("**********************************exception************************************\n");
		_log("LOCAL%d IndexError[local == NULL] spsel_server_author()", id);
		return false;
	}
	if(pLocal->m_nState != CClient::STATE_CONNECT)
	{
		_printf("**********************************exception************************************\n");
		_log("LOCAL%d StateError[state != STATE_CONNECT] spsel_server_author() > 泅犁 辑滚惑怕[%s]", pLocal->m_nIndex, pLocal->GetStateLog());
		return false;
	}

	IN_ADDR in_addr;
	in_addr.s_addr = pLocal->m_dwRemoteIP;

	sp->MCSetServerLogin.account = pLocal->m_nAccount;
	strcpy(sp->MCSetServerLogin.remote_ip, inet_ntoa(in_addr));

	sp->index = pLocal->m_nIndex;
	sp->sp_index = SPUPD_SERVER_LOGIN;
	g_cMasterServer.SetSp(sp);
	return true;
}

bool spsel_user_info(int id)
{
	SPINFO *sp = g_cMasterServer.GetSpObj();
	if(!sp)
	{
		_printf("**********************************exception************************************\n");
		_log("PC%d MempoolError[g_cMasterServer::GetSpObj() == NULL] spsel_user_info()", id);
		return false;
	}

	CUser *pUser = (CUser *)g_cMasterServer.GetClient(id);
	if(!pUser)
	{
		_printf("**********************************exception************************************\n");
		_log("PC%d IndexError[user == NULL] spsel_user_info()", id);
		return false;
	}
	if(pUser->m_nState != CClient::STATE_CONNECT)
	{
		_printf("**********************************exception************************************\n");
		_log("PC%d StateError[state != STATE_CONNECT] spsel_user_info() > 泅犁 蜡历惑怕[%s]", pUser->m_nIndex, pUser->GetStateLog());
		return false;
	}

	strcpy(sp->SAGetUserInfo.id, pUser->m_szID);

	sp->index = pUser->m_nIndex;
	sp->sp_index = SPSEL_USER_INFO;
	g_cMasterServer.SetSp(sp);
	return true;
}

bool spset_user_info(CADORecordset *pRec, int id)
{
	CUser *pUser = (CUser *)g_cMasterServer.GetClient(id);
	if(!pUser)
	{
		_printf("**********************************exception************************************\n");
		_log("PC%d IndexError[user == NULL] spset_user_info()", id);
		return false;
	}
	if(pUser->m_nState != CClient::STATE_CONNECT)
	{
		_printf("**********************************exception************************************\n");
		_log("PC%d StateError[state != STATE_CONNECT] spset_user_info() > 泅犁 蜡历惑怕[%s]", pUser->m_nIndex, pUser->GetStateLog());
		return false;
	}

	char uid[LEN_ID+1]={0,};
	char pwd[LEN_PWD+1]={0,};
	void *ioc;

	pRec->GetData(1, &pUser->m_nAccount, uid, pwd, pUser->m_szNick, &pUser->m_nGender, NULL);

	if(stricmp(pUser->m_szID, uid))
	{	//蜡历牢刘 角菩(酒捞叼 促抚) - 叼厚俊辑 ' '巩磊 牢侥救窍扁 锭巩俊 茄锅歹 厚背
		if((ioc = net_message(M_MASTERSERVER, MSC_USER_INFO, ERR_DIFFERENT_ID)))
		{
			if(!net_send(pUser->m_nIndex, ioc))
				net_disconnect(pUser->m_nIndex, false);
		}
		return false;
	}

	if(strcmp(pUser->m_szPwd, pwd))
	{	//蜡历牢刘 角菩(菩胶况靛 促抚)
		if((ioc = net_message(M_MASTERSERVER, MSC_USER_INFO, ERR_DIFFERENT_PWD)))
		{
			if(!net_send(pUser->m_nIndex, ioc))
				net_disconnect(pUser->m_nIndex, false);
		}
		return false;
	}

	strcpy(pUser->m_szID, uid);		//措家巩磊 备喊茄 盔贰 酒捞叼甫 持绰促
	return true;
}

bool spsel_game_info(int id)
{
	SPINFO *sp = g_cMasterServer.GetSpObj();
	if(!sp)
	{
		_printf("**********************************exception************************************\n");
		_log("PC%d MempoolError[g_cMasterServer::GetSpObj() == NULL] spsel_game_info()", id);
		return false;
	}

	CUser *pUser = (CUser *)g_cMasterServer.GetClient(id);
	if(!pUser)
	{
		_printf("**********************************exception************************************\n");
		_log("PC%d IndexError[user == NULL] spsel_game_info()", id);
		return false;
	}
	if(pUser->m_nState != CClient::STATE_CONNECT)
	{
		_printf("**********************************exception************************************\n");
		_log("PC%d StateError[state != STATE_CONNECT] spsel_game_info() > 泅犁 蜡历惑怕[%s]", pUser->m_nIndex, pUser->GetStateLog());
		return false;
	}

	sp->SAGetGameInfo.account = pUser->m_nAccount;

	sp->index = pUser->m_nIndex;
	sp->sp_index = SPSEL_GAME_INFO;
	g_cMasterServer.SetSp(sp);

	return true;
}

bool spset_game_info(CADORecordset *pRec, int id)
{
	CUser *pUser = (CUser *)g_cMasterServer.GetClient(id);
	if(!pUser)
	{
		_printf("**********************************exception************************************\n");
		_log("PC%d IndexError[user == NULL] spset_game_info()", id);
		return false;
	}
	if(pUser->m_nState != CClient::STATE_CONNECT)
	{
		_printf("**********************************exception************************************\n");
		_log("PC%d StateError[state != STATE_CONNECT] spset_game_info() > 泅犁 蜡历惑怕[%s]", pUser->m_nIndex, pUser->GetStateLog());
		return false;
	}

	UINT64 account, server;

	pRec->GetData(1, &account, pUser->m_szClan, &pUser->m_nPilot, &pUser->m_nLevel, &pUser->m_nExp,
		&pUser->m_cMechanic[0].account, &pUser->m_cMechanic[1].account, &pUser->m_cMechanic[2].account,
		&pUser->m_nCash, &pUser->m_nPoint, &pUser->m_dwBestPoint, &pUser->m_dwBestStraight,
		&pUser->m_dwWinStraight, &pUser->m_dwWin, &pUser->m_dwLose, &pUser->m_dwKill, &pUser->m_dwDeath,
		&pUser->m_dwRank, &pUser->m_dwQuit, &pUser->m_dwBlack, &server, NULL);

	if(pUser->m_nAccount != account)
	{
		_printf("**********************************exception************************************\n");
		_log("PC%d DBError[account != %I64d] spset_game_info() > 泅犁 蜡历拌沥[%I64d]", account, pUser->m_nAccount);
		return false;
	}

⌨️ 快捷键说明

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