238 lines
4.7 KiB
C
238 lines
4.7 KiB
C
|
|
/* vim: set filetype=c ts=8 noexpandtab: */
|
|
|
|
//#define COMPRESS_PRINT
|
|
|
|
#include "common.h"
|
|
#include "rakpeer.h"
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
__declspec(naked)
|
|
int __stdcall RakPeer__GetIndexFromPlayerID(
|
|
struct CRakPeer *this,
|
|
struct PlayerID playerId,
|
|
char calledFromNetworkThread)
|
|
{
|
|
_asm {
|
|
pop eax
|
|
pop ecx
|
|
push eax
|
|
mov eax, 0x453A40
|
|
jmp eax
|
|
}
|
|
}
|
|
|
|
__declspec(naked)
|
|
int __stdcall RakPeer__AddPacketToProducer(
|
|
struct CRakPeer *this,
|
|
struct CPacket *packet)
|
|
{
|
|
_asm {
|
|
pop eax
|
|
pop ecx
|
|
push eax
|
|
mov eax, 0x4523D0
|
|
jmp eax
|
|
}
|
|
}
|
|
|
|
__declspec(naked)
|
|
int __stdcall RakPeer__AssignPlayerIDToRemoteSystemList(
|
|
struct CRakPeer *this,
|
|
struct PlayerID playerId,
|
|
int connectionMode)
|
|
{
|
|
_asm {
|
|
pop eax
|
|
pop ecx
|
|
push eax
|
|
mov eax, 0x455E00
|
|
jmp eax
|
|
}
|
|
}
|
|
|
|
__declspec(naked)
|
|
struct CRemoteSystem* __stdcall RakPeer__GetRemoteSystemFromPlayerID(
|
|
struct CRakPeer *this,
|
|
struct PlayerID playerId,
|
|
char calledFromNetworkThread,
|
|
char onlyActive)
|
|
{
|
|
_asm {
|
|
pop eax
|
|
pop ecx
|
|
push eax
|
|
mov eax, 0x453AF0
|
|
jmp eax
|
|
}
|
|
}
|
|
|
|
static
|
|
int __declspec(naked) RakPeer__OnConnectionRequest(
|
|
struct CRakPeer *this,
|
|
struct CRemoteSystem *remoteSystem,
|
|
char *AESKey,
|
|
char setAESkey)
|
|
{
|
|
_asm {
|
|
mov eax, esp
|
|
pop ecx
|
|
push [eax+0x10] /*setAESKey*/
|
|
push [eax+0xC] /*AESKey*/
|
|
push [eax+0x8] /*remoteSystem*/
|
|
push ecx /*return address*/
|
|
mov ecx, [eax+0x4] /*this*/
|
|
mov eax, 0x455A60
|
|
jmp eax
|
|
}
|
|
}
|
|
|
|
__declspec(naked)
|
|
unsigned int __stdcall RakPeer__GetTime()
|
|
{
|
|
_asm {
|
|
mov eax, 0x44E9D0
|
|
jmp eax
|
|
}
|
|
}
|
|
|
|
static
|
|
void __declspec(naked) RakPeer__SendImmediate(
|
|
struct CRakPeer *this,
|
|
char *data,
|
|
int numberOfBitsToSend,
|
|
int priority,
|
|
int reliability,
|
|
int orderingChannel,
|
|
struct PlayerID playerId,
|
|
int broadcast,
|
|
int useCallerDataAllocation,
|
|
unsigned int currentTime)
|
|
{
|
|
_asm {
|
|
mov eax, esp
|
|
pop ecx
|
|
push [eax+0x30] // currentTimeDummy
|
|
push [eax+0x2C] // currentTime
|
|
push [eax+0x28] // useCallerDataAllocation
|
|
push [eax+0x24] // broadcast
|
|
push [eax+0x20] // playerId
|
|
push [eax+0x1C] // playerId
|
|
push [eax+0x18] // orderingChannel
|
|
push [eax+0x14] // reliability
|
|
push [eax+0x10] // priority
|
|
push [eax+0xC] // numberOfBitsToSend
|
|
push [eax+0x8] // data
|
|
push ecx /*return address*/
|
|
mov ecx, [eax+0x4] /*this*/
|
|
mov eax, 0x453C60
|
|
jmp eax
|
|
}
|
|
}
|
|
|
|
static
|
|
short __declspec(naked) RakPeer__AllowIncomingConnectionsInternal(
|
|
struct CRakPeer *this)
|
|
{
|
|
_asm {
|
|
mov ecx, [esp+0x4]
|
|
mov eax, 0x4509D0
|
|
call eax
|
|
ret
|
|
}
|
|
}
|
|
|
|
static
|
|
void RakPeer__ParseConnectionRequestPacketInternal(
|
|
struct CRakPeer *this,
|
|
struct CRemoteSystem *remoteSystem,
|
|
struct PlayerID playerId,
|
|
char *data,
|
|
char byteSize)
|
|
{
|
|
unsigned char responseData;
|
|
char *clientPass;
|
|
int clientPassLen;
|
|
char tmpPlayerDebugPassword[256];
|
|
|
|
printf("ParseConnectionRequestPacket start\n");
|
|
if (!RakPeer__AllowIncomingConnectionsInternal(this)) {
|
|
printf("server is full\n");
|
|
responseData = ID_NO_FREE_INCOMING_CONNECTIONS;
|
|
goto sendimmediateresponse;
|
|
}
|
|
|
|
printf("checking password requirements\n");
|
|
clientPassLen = byteSize - sizeof(char);
|
|
clientPass = data + sizeof(char);
|
|
if (this->incomingPasswordLength != clientPassLen) {
|
|
printf("incorrect password length\n");
|
|
printf("client: %d server: %d\n",
|
|
clientPassLen, this->incomingPasswordLength);
|
|
goto kickplayer;
|
|
}
|
|
if (memcmp(this->incomingPassword, clientPass, clientPassLen) != 0) {
|
|
printf("non-matching password\n");
|
|
/*temp copy player password to print, because it's not zero
|
|
termd*/
|
|
memcpy(tmpPlayerDebugPassword, clientPass, clientPassLen);
|
|
tmpPlayerDebugPassword[clientPassLen] = 0;
|
|
printf("client: %s server: %s\n",
|
|
tmpPlayerDebugPassword, this->incomingPassword);
|
|
goto kickplayer;
|
|
}
|
|
printf("password check passed\n");
|
|
|
|
/*security is not used*/
|
|
/*if (this->usingSecurity) {
|
|
printf("using security\n");
|
|
//SecuredConnectionResponse(playerId);
|
|
goto ret;
|
|
}*/
|
|
RakPeer__OnConnectionRequest(this, remoteSystem, NULL, 0);
|
|
goto ret;
|
|
|
|
kickplayer:
|
|
responseData = ID_INVALID_PASSWORD;
|
|
sendimmediateresponse:
|
|
printf("disconnecting player\n");
|
|
RakPeer__SendImmediate(
|
|
this,
|
|
&responseData,
|
|
sizeof(char) * 8,
|
|
SYSTEM_PRIORITY,
|
|
RELIABLE,
|
|
0,
|
|
playerId,
|
|
0,
|
|
0,
|
|
RakPeer__GetTime(),
|
|
0
|
|
);
|
|
remoteSystem->connectMode = DISCONNECT_ASAP_SILENTLY;
|
|
ret:
|
|
printf("ParseConnectionRequestPacket end\n");
|
|
}
|
|
|
|
int __declspec(naked) RakPeer__ParseConnectionRequestPacket(
|
|
struct CRakPeer__RemoteSystemStruct *remoteSystem,
|
|
struct PlayerID playerId,
|
|
int data,
|
|
char byteSize)
|
|
{
|
|
_asm {
|
|
mov eax, esp
|
|
push [eax+0x14] // byteSize
|
|
push [eax+0x10] // data
|
|
push [eax+0xC] // playerId
|
|
push [eax+0x8] // playerId
|
|
push [eax+0x4] // remoteSystem
|
|
push ecx // this
|
|
call RakPeer__ParseConnectionRequestPacketInternal
|
|
add esp, 0x18
|
|
retn 0x14 /*+4 for playerid*/
|
|
}
|
|
}
|