From bd3a6a04601749cbde007eaabf803fb602ee2783 Mon Sep 17 00:00:00 2001 From: fusion32 Date: Thu, 19 Jun 2025 03:13:48 -0300 Subject: beginning of `communication.cc` --- reference/game.c | 406 ----------------------------------------------------- reference/types.hh | 52 ------- 2 files changed, 458 deletions(-) (limited to 'reference') diff --git a/reference/game.c b/reference/game.c index 3711e19..acbdbfa 100644 --- a/reference/game.c +++ b/reference/game.c @@ -37401,412 +37401,6 @@ void __static_initialization_and_destruction_0(int __initialize_p,int __priority return; } - - -// WARNING: Unknown calling convention -- yet parameter storage is locked - -void InitCommunicationThreadStacks(void) - -{ - int i; - int iVar1; - - if (UseOwnStacks) { - memset(CommunicationThreadStacks,0xaa,0x44c0000); - iVar1 = 0; - do { - LastUsingCommunicationThread[iVar1] = 0; - FreeCommunicationThreadStacks[iVar1] = iVar1; - iVar1 = iVar1 + 1; - } while (iVar1 < 0x44c); - NumberOfFreeCommunicationThreadStacks = 0x44c; - } - return; -} - - - -// WARNING: Variable defined which should be unmapped: Stack_local - -void GetCommunicationThreadStack(int *StackNumber,void **Stack) - -{ - int iVar1; - int iVar2; - int Number; - int i; - int iVar3; - bool bVar4; - void **Stack_local; - - if (!UseOwnStacks) { - error(&DAT_0810b9a0); - *StackNumber = -1; - *Stack = (void *)0x0; - return; - } - iVar3 = 0; - Semaphore::down(&CommunicationThreadMutex); - *StackNumber = -1; - bVar4 = 0 < NumberOfFreeCommunicationThreadStacks; - *Stack = (void *)0x0; - if (bVar4) { - do { - iVar1 = FreeCommunicationThreadStacks[iVar3]; - if (LastUsingCommunicationThread[iVar1] == 0) { -LAB_080dbcd6: - *StackNumber = iVar1; - NumberOfFreeCommunicationThreadStacks = NumberOfFreeCommunicationThreadStacks + -1; - *Stack = CommunicationThreadStacks + iVar1 * 0x10000; - FreeCommunicationThreadStacks[iVar3] = - FreeCommunicationThreadStacks[NumberOfFreeCommunicationThreadStacks]; - break; - } - iVar2 = kill(LastUsingCommunicationThread[iVar1],0); - if (iVar2 == -1) goto LAB_080dbcd6; - iVar3 = iVar3 + 1; - } while (iVar3 < NumberOfFreeCommunicationThreadStacks); - } - Semaphore::up(&CommunicationThreadMutex); - return; -} - - - -void AttachCommunicationThreadStack(int StackNumber) - -{ - __pid_t _Var1; - - _Var1 = getpid(); - LastUsingCommunicationThread[StackNumber] = _Var1; - return; -} - - - -void ReleaseCommunicationThreadStack(int StackNumber) - -{ - Semaphore::down(&CommunicationThreadMutex); - FreeCommunicationThreadStacks[NumberOfFreeCommunicationThreadStacks] = StackNumber; - NumberOfFreeCommunicationThreadStacks = NumberOfFreeCommunicationThreadStacks + 1; - Semaphore::up(&CommunicationThreadMutex); - return; -} - - - -// WARNING: Unknown calling convention -- yet parameter storage is locked - -void ExitCommunicationThreadStacks(void) - -{ - int i; - int iVar1; - int HighestStackAddress; - int iVar2; - int LowestStackAddress; - int iVar3; - int Stack; - int iVar4; - - if (UseOwnStacks) { - if (NumberOfFreeCommunicationThreadStacks != 0x44c) { - error("FreeCommunicationThreadStacks: Nicht alle Stacks freigegeben.\n"); - } - iVar2 = -1; - iVar3 = 0x10000; - iVar4 = 0; - do { - iVar1 = 0; - do { - if (CommunicationThreadStacks[iVar4 * 0x10000 + iVar1] != 0xaa) { - if (iVar2 < iVar1) { - iVar2 = iVar1; - } - if (iVar1 < iVar3) { - iVar3 = iVar1; - } - } - iVar1 = iVar1 + 1; - } while (iVar1 < 0x10000); - iVar4 = iVar4 + 1; - } while (iVar4 < 0x44c); - if (0x10000 - (iVar2 - iVar3) < 0x8000) { - error("Maximale Stack-Ausdehnung: %d..%d\n",iVar3,iVar2); - } - } - return; -} - - - -// WARNING: Unknown calling convention -- yet parameter storage is locked - -void InitLoadHistory(void) - -{ - int i; - int iVar1; - - iVar1 = 0; - do { - LoadHistory[iVar1] = 0; - iVar1 = iVar1 + 1; - } while (iVar1 < 0x168); - LoadHistoryPointer = 0; - TotalSend = 0; - TotalLoad = 0; - LagEnd = 0; - TotalRecv = 0; - EarliestFreeAccountAdmissionRound = 0; - InitLog("netload"); - return; -} - - - -// WARNING: Unknown calling convention -- yet parameter storage is locked - -bool LagDetected(void) - -{ - return RoundNr <= LagEnd; -} - - - -void NetLoad(int Amount,bool Send) - -{ - Semaphore::down(&CommunicationThreadMutex); - if (Send) { - TotalSend = TotalSend + Amount; - } - else { - TotalRecv = TotalRecv + Amount; - } - Semaphore::up(&CommunicationThreadMutex); - return; -} - - - -// WARNING: Unknown calling convention -- yet parameter storage is locked - -void NetLoadSummary(void) - -{ - Semaphore::down(&CommunicationThreadMutex); - Log("netload","gesendet: %d Bytes.\n",TotalSend); - Log("netload","empfangen: %d Bytes.\n",TotalRecv); - TotalSend = 0; - TotalRecv = 0; - Semaphore::up(&CommunicationThreadMutex); - return; -} - - - -// WARNING: Unknown calling convention -- yet parameter storage is locked - -void NetLoadCheck(void) - -{ - int Delay; - int iVar1; - TConnection *this; - ulong *puVar2; - TConnection *Connection; - int iVar3; - int DeltaRecv; - int iVar4; - uint local_c; - - iVar4 = NetLoadCheck::LastRecv; - NetLoadCheck::LastRecv = TotalRecv; - iVar4 = TotalRecv - iVar4; - if (-1 < iVar4) { - iVar1 = GetPlayersOnline(); - if (iVar1 == 0) { - iVar4 = 0; - } - else { - iVar1 = GetPlayersOnline(); - iVar4 = iVar4 / iVar1; - } - iVar1 = LoadHistory[LoadHistoryPointer]; - LoadHistory[LoadHistoryPointer] = iVar4; - iVar3 = LoadHistoryPointer + 1; - TotalLoad = (TotalLoad - iVar1) + iVar4; - LoadHistoryPointer = 0; - if (iVar3 != 0x168) { - LoadHistoryPointer = iVar3; - } - if (((0xe0f < RoundNr) && (iVar1 = GetPlayersOnline(), 0x31 < iVar1)) && - (iVar4 < TotalLoad / 0x2d0)) { - Log("game","Lag erkannt!\n"); - LagEnd = RoundNr + 0x1e; - if (PremiumPlayerBuffer == 0) { - iVar4 = 0x3c; - } - else { - iVar4 = GetPlayersOnline(); - iVar4 = ((iVar4 - (MaxPlayers + PremiumPlayerBuffer * -2)) * 0x1e) / - PremiumPlayerBuffer; - } - local_c = iVar4 + RoundNr; - puVar2 = &EarliestFreeAccountAdmissionRound; - if (EarliestFreeAccountAdmissionRound < iVar4 + RoundNr) { - puVar2 = &local_c; - } - EarliestFreeAccountAdmissionRound = *puVar2; - this = GetFirstConnection(); - while (this != (TConnection *)0x0) { - if (this->State - CONNECTION_LOGIN < 4) { - TConnection::EmergencyPing(this); - } - this = GetNextConnection(); - } - } - } - return; -} - - - -bool WriteToSocket(TConnection *Connection,uchar *Buffer,int Size) - -{ - uchar *__block; - int iVar1; - ssize_t sVar2; - int *piVar3; - int Offset; - size_t __n; - int in_stack_ffffffbc; - int local_30; - int Chances; - TWriteBuffer WriteBuffer; - - if ((Size & 7U) != 0) { - do { - iVar1 = rand_r(&Connection->RandomSeed); - Buffer[Size + 2] = (uchar)iVar1; - Size = Size + 1; - } while ((Size & 7U) != 0); - } - __n = Size + 2; - iVar1 = 2; - if (2 < (int)__n) { - do { - __block = Buffer + iVar1; - iVar1 = iVar1 + 8; - TXTEASymmetricKey::encrypt(&Connection->SymmetricKey,(char *)__block,in_stack_ffffffbc); - } while (iVar1 < (int)__n); - } - TWriteBuffer::TWriteBuffer((TWriteBuffer *)&Chances,Buffer,__n); - TWriteBuffer::writeWord((TWriteBuffer *)&Chances,(ushort)Size); - local_30 = 0x32; -joined_r0x080dc15b: - if ((int)__n < 1) { - Semaphore::down(&CommunicationThreadMutex); - TotalSend = TotalSend + Size + 0x32U; - Semaphore::up(&CommunicationThreadMutex); - return true; - } - iVar1 = TConnection::GetSocket(Connection); - sVar2 = write(iVar1,Buffer,__n); - if (sVar2 == -1) goto LAB_080dc1f0; - goto LAB_080dc182; -LAB_080dc1f0: - piVar3 = __errno_location(); - if (*piVar3 != 4) { - if ((*piVar3 != 0xb) || (local_30 < 1)) { - piVar3 = __errno_location(); - iVar1 = *piVar3; - if (((iVar1 == 0x68) || (iVar1 == 0x20)) || (iVar1 == 0xb)) { - iVar1 = TConnection::GetSocket(Connection); - Log("game","Verbindung an Socket %d zusammengebrochen.\n",iVar1); - } - else { -LAB_080dc182: - if (0 < sVar2) { - __n = __n - sVar2; - Buffer = Buffer + sVar2; - goto joined_r0x080dc15b; - } - iVar1 = TConnection::GetSocket(Connection); - piVar3 = __errno_location(); - error("WriteToSocket: Fehler %d beim Senden an Socket %d.\n",*piVar3,iVar1); - } - return false; - } - DelayThread(0,100000); - local_30 = local_30 + -1; - } - goto joined_r0x080dc15b; -} - - - -bool SendLoginMessage(TConnection *Connection,int Type,char *Message,int WaitingTime) - -{ - int Size; - bool bVar1; - size_t sVar2; - char *Text; - undefined1 local_15c [4]; - TWriteBuffer Buffer; - uchar Data [302]; - - if (Type - 0x14U < 3) { - if (Message == (char *)0x0) { - error("SendLoginMessage: Message ist NULL.\n"); - return true; - } - if (Type == 0x16) { - bVar1 = false; - if ((0 < WaitingTime) && (WaitingTime < 0x100)) { - bVar1 = true; - } - if (!bVar1) { - Text = &DAT_0810bb40; - goto LAB_080dc3c0; - } - } - // try { // try from 080dc2d0 to 080dc390 has its CatchHandler @ 080dc3f0 - TWriteBuffer::TWriteBuffer - ((TWriteBuffer *)local_15c,(uchar *)((int)&Buffer.Position + 2),300); - TWriteBuffer::writeWord((TWriteBuffer *)local_15c,0); - TWriteBuffer::writeByte((TWriteBuffer *)local_15c,(uchar)Type); - sVar2 = strlen(Message); - if (sVar2 < 0x123) { - TWriteStream::writeString((TWriteStream *)local_15c,Message); - if (Type == 0x16) { - TWriteBuffer::writeByte((TWriteBuffer *)local_15c,(uchar)WaitingTime); - } - Size = Buffer.Size; - Buffer.Size = 0; - TWriteBuffer::writeWord((TWriteBuffer *)local_15c,(short)Size - 2); - bVar1 = WriteToSocket(Connection,(uchar *)&Buffer.Position,Size); - return bVar1; - } - error("SendLoginMessage: Botschaft zu lang (%s).\n",Message); - } - else { - Text = &DAT_0810bbc0; - WaitingTime = Type; -LAB_080dc3c0: - error(Text,WaitingTime); - } - return true; -} - - - bool SendData(TConnection *Connection) { diff --git a/reference/types.hh b/reference/types.hh index ef66baf..8e749d8 100644 --- a/reference/types.hh +++ b/reference/types.hh @@ -1,9 +1,4 @@ -struct TXTEASymmetricKey { - int (**_vptr.TXTEASymmetricKey)(...); // VTABLE? - uchar m_SymmetricKey[16]; -}; - struct TDatabasePoolConnection { TDatabaseConnectionPool *DatabaseConnectionPool; TDatabaseConnection *DatabaseConnection; @@ -60,15 +55,6 @@ struct THouse { int Help; }; -struct TWaitinglistEntry { - struct TWaitinglistEntry *Next; - char Name[30]; - ulong NextTry; - bool FreeAccount; - bool Newbie; - bool Sleeping; -}; - struct TDelayedMail { ulong CharacterID; int DepotNumber; @@ -224,41 +210,3 @@ struct TReaderThreadReply { uchar *Data; int Size; }; - -// NOTE(fusion): Probably bigint structures for RSA decoding. -struct vlong_flex_unit { - uint n; - uint *a; - uint z; -}; - -struct vlong { - int (**_vptr.vlong)(...); - struct vlong_value *value; - int negative; -}; - -struct vlong_value { - struct vlong_flex_unit super_vlong_flex_unit; - uint share; -}; - -struct vlong_montgomery { - struct vlong R; - struct vlong R1; - struct vlong m; - struct vlong n1; - struct vlong T; - struct vlong k; - uint N; -}; - -// NOTE(fusion): Oh yes. -struct TRSAPrivateKey { - int (**_vptr.TRSAPrivateKey)(...); - struct vlong m_PrimeP; - struct vlong m_PrimeQ; - struct vlong m_U; - struct vlong m_DP; - struct vlong m_DQ; -}; -- cgit v1.2.3