From d3b92e110a06c6bb2bc0214319b390059bdf7c4a Mon Sep 17 00:00:00 2001 From: fusion32 Date: Fri, 20 Jun 2025 06:00:16 -0300 Subject: more work on `communication.cc` --- reference/game.c | 1165 ------------------------------------------------------ 1 file changed, 1165 deletions(-) (limited to 'reference') diff --git a/reference/game.c b/reference/game.c index acbdbfa..71343d6 100644 --- a/reference/game.c +++ b/reference/game.c @@ -37401,1171 +37401,6 @@ void __static_initialization_and_destruction_0(int __initialize_p,int __priority return; } -bool SendData(TConnection *Connection) - -{ - int iVar1; - undefined1 *puVar2; - bool bVar3; - uint uVar4; - int Offset; - int iVar5; - int DataSize; - uint uVar6; - undefined4 uStackY_50; - uint auStack_48 [2]; - undefined1 auStack_40 [8]; - undefined1 *local_38; - uchar_0_ *Buffer; - int local_30; - int PacketSize; - TWriteBuffer WriteBuffer; - - Buffer = &stack0xffffffb4; - if (Connection == (TConnection *)0x0) { - uStackY_50 = 0x80dc573; - error("SendData: Verbindung ist NULL.\n"); - } - else { - uVar6 = Connection->NextToCommit - Connection->NextToSend; - uVar4 = uVar6 + 0xe; - if (-1 < (int)(uVar6 + 7)) { - uVar4 = uVar6 + 7; - } - uVar4 = uVar4 & 0xfffffff8; - local_30 = uVar4 + 2; - iVar1 = -(uVar4 + 0x13 & 0xfffffff0); - local_38 = auStack_40 + iVar1; - *(uint *)((int)auStack_48 + iVar1 + 4) = uVar4 + 4; - *(undefined1 **)((int)auStack_48 + iVar1) = auStack_40 + iVar1; - *(int **)(&stack0xffffffb4 + iVar1) = &PacketSize; - *(undefined4 *)((int)&uStackY_50 + iVar1) = 0x80dc48e; - TWriteBuffer::TWriteBuffer - (*(TWriteBuffer **)(&stack0xffffffb4 + iVar1),*(uchar **)((int)auStack_48 + iVar1) - ,*(int *)((int)auStack_48 + iVar1 + 4)); - *(undefined4 *)((int)auStack_48 + iVar1) = 0; - *(int **)(&stack0xffffffb4 + iVar1) = &PacketSize; - *(undefined4 *)((int)&uStackY_50 + iVar1) = 0x80dc4a1; - TWriteBuffer::writeWord - (*(TWriteBuffer **)(&stack0xffffffb4 + iVar1),*(ushort *)((int)auStack_48 + iVar1) - ); - *(uint *)((int)auStack_48 + iVar1) = uVar6 & 0xffff; - *(int **)(&stack0xffffffb4 + iVar1) = &PacketSize; - *(undefined4 *)((int)&uStackY_50 + iVar1) = 0x80dc4b3; - TWriteBuffer::writeWord - (*(TWriteBuffer **)(&stack0xffffffb4 + iVar1),*(ushort *)((int)auStack_48 + iVar1) - ); - iVar5 = Connection->NextToSend % 0x4000; - if ((int)(uVar6 + iVar5) < 0x4001) { - *(uint *)((int)auStack_48 + iVar1 + 4) = uVar6; - *(uchar **)((int)auStack_48 + iVar1) = Connection->OutData + iVar5; - *(int **)(&stack0xffffffb4 + iVar1) = &PacketSize; - } - else { - *(uchar **)((int)auStack_48 + iVar1) = Connection->OutData + iVar5; - *(int **)(&stack0xffffffb4 + iVar1) = &PacketSize; - *(int *)((int)auStack_48 + iVar1 + 4) = 0x4000 - iVar5; - *(undefined4 *)((int)&uStackY_50 + iVar1) = 0x80dc4f9; - TWriteBuffer::writeBytes - (*(TWriteBuffer **)(&stack0xffffffb4 + iVar1), - *(uchar **)((int)auStack_48 + iVar1),*(int *)((int)auStack_48 + iVar1 + 4)); - *(uint *)((int)auStack_48 + iVar1 + 4) = uVar6 + iVar5 + -0x4000; - *(uchar **)((int)auStack_48 + iVar1) = Connection->OutData; - *(int **)(&stack0xffffffb4 + iVar1) = &PacketSize; - } - *(undefined4 *)((int)&uStackY_50 + iVar1) = 0x80dc518; - TWriteBuffer::writeBytes - (*(TWriteBuffer **)(&stack0xffffffb4 + iVar1),*(uchar **)((int)auStack_48 + iVar1) - ,*(int *)((int)auStack_48 + iVar1 + 4)); - *(int *)((int)auStack_48 + iVar1 + 4) = local_30; - puVar2 = local_38; - *(TConnection **)(&stack0xffffffb4 + iVar1) = Connection; - *(undefined1 **)((int)auStack_48 + iVar1) = puVar2; - *(undefined4 *)((int)&uStackY_50 + iVar1) = 0x80dc52e; - bVar3 = WriteToSocket(*(TConnection **)(&stack0xffffffb4 + iVar1), - *(uchar **)((int)auStack_48 + iVar1), - *(int *)((int)auStack_48 + iVar1 + 4)); - if (bVar3) { - Connection->NextToSend = Connection->NextToSend + uVar6; - return true; - } - } - return false; -} - - - -bool SendData(TConnection *Connection,char *Data,int Size) - -{ - bool bVar1; - - if (Connection == (TConnection *)0x0) { - error("SendData: Connection ist NULL.\n"); - bVar1 = false; - } - else if (Data == (char *)0x0) { - error("SendData: Data ist NULL.\n"); - bVar1 = true; - } - else { - memcpy(Connection->OutData + 2,Data,Size); - Connection->NextToSend = 0; - Connection->NextToCommit = Size + 2; - bVar1 = SendData(Connection); - } - return bVar1; -} - - - -// WARNING: Unknown calling convention -- yet parameter storage is locked - -bool GetWaitinglistEntry(void) - -{ - TWaitinglistEntry *pTVar1; - int iVar2; - TWaitinglistEntry *Search; - char *in_stack_00000004; - ulong *in_stack_00000008; - undefined1 *in_stack_0000000c; - undefined1 *in_stack_00000010; - - Semaphore::down(&CommunicationThreadMutex); - pTVar1 = WaitinglistHead; - while( true ) { - if (pTVar1 == (TWaitinglistEntry *)0x0) { - Semaphore::up(&CommunicationThreadMutex); - return false; - } - iVar2 = stricmp(in_stack_00000004,pTVar1->Name,-1); - if (iVar2 == 0) break; - pTVar1 = pTVar1->Next; - } - *in_stack_00000008 = pTVar1->NextTry; - *in_stack_0000000c = pTVar1->FreeAccount; - *in_stack_00000010 = pTVar1->Newbie; - Semaphore::up(&CommunicationThreadMutex); - return true; -} - - - -// WARNING: Variable defined which should be unmapped: NextTry_local - -void InsertWaitinglistEntry(char *Name,ulong NextTry,bool FreeAccount,bool Newbie) - -{ - TWaitinglistEntry *pTVar1; - int iVar2; - TWaitinglistEntry *pTVar3; - TWaitinglistEntry *Entry; - TWaitinglistEntry *Last; - bool Newbie_local; - bool FreeAccount_local; - ulong NextTry_local; - - Semaphore::down(&CommunicationThreadMutex); - pTVar1 = (TWaitinglistEntry *)0x0; - pTVar3 = WaitinglistHead; - while( true ) { - if (pTVar3 == (TWaitinglistEntry *)0x0) { - pTVar3 = store<>::getFreeItem(&Waitinglist); - strcpy(pTVar3->Name,Name); - pTVar3->NextTry = NextTry; - pTVar3->FreeAccount = FreeAccount; - pTVar3->Next = (TWaitinglistEntry *)0x0; - pTVar3->Sleeping = false; - pTVar3->Newbie = Newbie; - if (pTVar1 != (TWaitinglistEntry *)0x0) { - pTVar1->Next = pTVar3; - pTVar3 = WaitinglistHead; - } - WaitinglistHead = pTVar3; - Semaphore::up(&CommunicationThreadMutex); - Log("queue",&DAT_0810bc80); - return; - } - iVar2 = stricmp(Name,pTVar3->Name,-1); - if (iVar2 == 0) break; - pTVar1 = pTVar3; - pTVar3 = pTVar3->Next; - } - pTVar3->NextTry = NextTry; - pTVar3->FreeAccount = FreeAccount; - pTVar3->Newbie = Newbie; - Semaphore::up(&CommunicationThreadMutex); - return; -} - - - -void DeleteWaitinglistEntry(char *Name) - -{ - TWaitinglistEntry *pTVar1; - TWaitinglistEntry *pTVar2; - int iVar3; - TWaitinglistEntry *Search; - TWaitinglistEntry *Entry; - storeitem<> *psVar4; - - psVar4 = (storeitem<> *)0x0; - Semaphore::down(&CommunicationThreadMutex); - if (WaitinglistHead != (TWaitinglistEntry *)0x0) { - iVar3 = stricmp(Name,WaitinglistHead->Name,-1); - if (iVar3 == 0) { - psVar4 = (storeitem<> *)WaitinglistHead; - WaitinglistHead = WaitinglistHead->Next; - } - else if (WaitinglistHead != (TWaitinglistEntry *)0x0) { - pTVar1 = WaitinglistHead->Next; - pTVar2 = WaitinglistHead; - while (pTVar1 != (TWaitinglistEntry *)0x0) { - iVar3 = stricmp(Name,pTVar2->Next->Name,-1); - if (iVar3 == 0) { - psVar4 = (storeitem<> *)pTVar2->Next; - pTVar2->Next = (TWaitinglistEntry *)psVar4->next; - break; - } - pTVar2 = pTVar2->Next; - pTVar1 = pTVar2->Next; - } - } - } - if (psVar4 != (storeitem<> *)0x0) { - psVar4->next = Waitinglist.firstFreeItem; - Waitinglist.firstFreeItem = psVar4; - } - Semaphore::up(&CommunicationThreadMutex); - return; -} - - - -// WARNING: Variable defined which should be unmapped: Newbie_local - -int GetWaitinglistPosition(char *Name,bool FreeAccount,bool Newbie) - -{ - int iVar1; - int iVar2; - storeitem<> *psVar3; - TWaitinglistEntry *Search; - storeitem<> *psVar4; - int PremiumVeterans; - int iVar5; - int PremiumNewbies; - int iVar6; - int local_1c; - int FreeVeterans; - int FreeNewbies; - bool Newbie_local; - bool FreeAccount_local; - - iVar6 = 0; - iVar5 = 0; - local_1c = 0; - FreeVeterans = 0; - Semaphore::down(&CommunicationThreadMutex); - psVar3 = (storeitem<> *)WaitinglistHead; - if ((WaitinglistHead != (TWaitinglistEntry *)0x0) && (WaitinglistHead->NextTry + 0x3c < RoundNr) - ) { - do { - psVar4 = psVar3; - Log("queue",&DAT_0810bcc0,(psVar4->data).Name); - psVar3 = (storeitem<> *)WaitinglistHead->Next; - WaitinglistHead = (TWaitinglistEntry *)psVar3; - psVar4->next = Waitinglist.firstFreeItem; - Waitinglist.firstFreeItem = psVar4; - if (psVar3 == (storeitem<> *)0x0) break; - } while ((psVar3->data).NextTry + 0x3c < RoundNr); - } - if (psVar3 != (storeitem<> *)0x0) { - iVar5 = 0; - do { - iVar1 = stricmp(Name,(psVar3->data).Name,-1); - if (iVar1 == 0) break; - iVar1 = local_1c; - if ((psVar3->data).Sleeping == false) { - if ((psVar3->data).NextTry + 5 < RoundNr) { - (psVar3->data).Sleeping = true; - } - else if ((psVar3->data).FreeAccount == false) { - if ((psVar3->data).Newbie != false) { - iVar6 = iVar6 + 1; - } - if ((psVar3->data).Newbie == false) { - iVar5 = iVar5 + 1; - } - } - else { - iVar2 = FreeVeterans + 1; - if ((psVar3->data).Newbie == false) { - iVar2 = FreeVeterans; - } - iVar1 = local_1c + 1; - FreeVeterans = iVar2; - if ((psVar3->data).Newbie != false) { - iVar1 = local_1c; - } - } - } - local_1c = iVar1; - psVar3 = psVar3->next; - } while (psVar3 != (storeitem<> *)0x0); - } - Semaphore::up(&CommunicationThreadMutex); - if (FreeAccount) { - if (Newbie) { - local_1c = iVar5 + 1 + FreeVeterans + local_1c + iVar6; - } - else { - local_1c = iVar5 + 1 + local_1c; - iVar5 = GetNewbiesOnline(); - if (iVar5 < MaxNewbies - PremiumNewbieBuffer) { - local_1c = FreeVeterans + local_1c; - } - } - } - else { - local_1c = iVar5 + 1 + iVar6; - if (!Newbie) { - iVar1 = GetNewbiesOnline(); - local_1c = iVar5 + 1; - if (iVar1 < MaxNewbies) { - local_1c = iVar6 + iVar5 + 1; - } - } - } - return local_1c; -} - - - -int CheckWaitingTime(char *Name,TConnection *Connection,bool FreeAccount,bool Newbie) - -{ - int iVar1; - int iVar2; - int iVar3; - int iVar4; - int PlayersOnline; - int Position; - int WaitingTime; - int WaitingTime_00; - int NewbiesOnline; - char *Reason; - char local_11c [2]; - bool Newbie_local; - bool FreeAccount_local; - char Message [250]; - - WaitingTime_00 = 0; - NewbiesOnline = 0; - iVar1 = GetWaitinglistPosition(Name,FreeAccount,Newbie); - iVar2 = GetPlayersOnline(); - iVar3 = GetNewbiesOnline(); - iVar4 = GetOrderBufferSpace(); - if (iVar4 - iVar1 < iVar2) { - print(); - NewbiesOnline = (int)s_The_server_is_overloaded__0810d5ea; - WaitingTime_00 = iVar1 / 2 + 10; - goto LAB_080dcb50; - } - if (FreeAccount) { - if (RoundNr < EarliestFreeAccountAdmissionRound) { - print(); - NewbiesOnline = (int)s_The_server_is_overloaded__Only_p_0810bf60; - WaitingTime_00 = iVar1 / 2 + (EarliestFreeAccountAdmissionRound - RoundNr); - goto LAB_080dcb50; - } - if (iVar2 <= (MaxPlayers - PremiumPlayerBuffer) - iVar1) goto LAB_080dcaff; - print(); - NewbiesOnline = (int)s_Too_many_players_online__Only_pl_0810bec0; -LAB_080dcbd5: - WaitingTime_00 = iVar1 / 2 + 5; - } - else { - if (MaxPlayers - iVar1 < iVar2) { - print(); - NewbiesOnline = (int)s_There_are_too_many_players_onlin_0810bfc0; - } - else { -LAB_080dcaff: - if (!Newbie) goto LAB_080dcb50; - if ((FreeAccount) || (iVar3 <= MaxNewbies - iVar1)) { - if ((!Newbie) || - ((!FreeAccount || (iVar3 <= (MaxNewbies - PremiumNewbieBuffer) - iVar1)))) - goto LAB_080dcb50; - print(); - NewbiesOnline = (int)s_There_are_too_many_players_onlin_0810bd80; - goto LAB_080dcbd5; - } - print(); - NewbiesOnline = (int)s_There_are_too_many_players_onlin_0810be20; - } - WaitingTime_00 = iVar1 / 2 + 3; - } -LAB_080dcb50: - if (0xf0 < WaitingTime_00) { - WaitingTime_00 = 0xf0; - } - if (0 < WaitingTime_00) { - snprintf(local_11c,0xfa,"%s\n\nYou are at place %d on the waiting list.",NewbiesOnline,iVar1 - ); - SendLoginMessage(Connection,0x16,local_11c,WaitingTime_00); - } - return WaitingTime_00; -} - - - -// WARNING: Variable defined which should be unmapped: Chances - -int ReadFromSocket(TConnection *Connection,uchar *Buffer,int Size) - -{ - int __fd; - ssize_t sVar1; - int *piVar2; - int nread; - int nleft; - size_t __nbytes; - int local_14; - int Chances; - - local_14 = 0x32; - __nbytes = Size; - if (0 < Size) { - do { - __fd = TConnection::GetSocket(Connection); - sVar1 = read(__fd,Buffer,__nbytes); - if (sVar1 == 0) break; - if (sVar1 < 0) { - piVar2 = __errno_location(); - if (*piVar2 != 4) { - if (*piVar2 != 0xb) { - return sVar1; - } - if (__nbytes == Size) { - return sVar1; - } - if (local_14 == 0) { - return sVar1; - } - local_14 = local_14 + -1; - usleep(100000); - } - } - else { - __nbytes = __nbytes - sVar1; - Buffer = Buffer + sVar1; - } - } while (0 < (int)__nbytes); - } - return Size - __nbytes; -} - - - -bool CallGameThread(TConnection *Connection) - -{ - bool bVar1; - pid_t pVar2; - int iVar3; - - bVar1 = GameRunning(); - if (bVar1) { - Connection->WaitingForACK = true; - pVar2 = GetGameThreadPID(); - iVar3 = kill(pVar2,10); - if (iVar3 != 0) { - pVar2 = GetGameThreadPID(); - error("CallGameThread: Can\'t send SIGUSR1 to pid %d\n",pVar2); - SendLoginMessage(Connection,0x14,"The server is not online.\nPlease try again later.",-1 - ); - return false; - } - } - return true; -} - - - -bool CheckConnection(TConnection *Connection) - -{ - int iVar1; - bool bVar2; - undefined1 local_14 [4]; - pollfd Status; - - bVar2 = false; - local_14 = (undefined1 [4])TConnection::GetSocket(Connection); - Status.fd._0_2_ = 1; - iVar1 = poll((pollfd *)local_14,1,0); - if ((-1 < iVar1) && ((Status.fd._2_2_ & 1) == 0)) { - bVar2 = true; - } - return bVar2; -} - - - -TPlayerData * -PerformRegistration(TConnection *Connection,char *PlayerName,ulong AccountID,char *PlayerPassword, - bool GamemasterClient) - -{ - int iVar1; - char *pcVar2; - TPlayerData *pTVar3; - __pid_t _Var4; - TPlayerData *PlayerData; - char (*__dest) [30]; - bool bVar5; - int iVar6; - int local_e18; - int local_e14; - int i; - undefined1 auStack_e0c [2]; - bool ReadOnly; - bool GamemasterClient_local; - pollfd Status_1; - ulong CharacterID; - int Sex; - int NumberOfBuddies; - undefined1 auStack_df4 [3]; - bool PremiumAccountActivated; - pollfd Status; - char BuddyNames [100] [30]; - char local_22c [4]; - char Title [31]; - char Rank [31]; - char Guild [31]; - ulong BuddyIDs [100]; - uchar Rights [12]; - undefined1 local_2c [4]; - TQueryManagerPoolConnection QueryManagerConnection; - - TQueryManagerPoolConnection::TQueryManagerPoolConnection - ((TQueryManagerPoolConnection *)local_2c,&QueryManagerConnectionPool); - if (QueryManagerConnection.QueryManagerConnectionPool == (TQueryManagerConnectionPool *)0x0) { - pcVar2 = "PerformRegistration: Kann Verbindung zum Query-Manager nicht herstellen.\n"; -LAB_080dd3a0: - error(pcVar2); -switchD_080dcfed_caseD_0: - pcVar2 = "Internal error, closing connection."; - goto LAB_080dd020; - } - // try { // try from 080dceb0 to 080dd02f has its CatchHandler @ 080dd590 - _auStack_df4 = TConnection::GetSocket(Connection); - bVar5 = false; - Status.fd._0_2_ = 1; - iVar6 = 1; - iVar1 = poll((pollfd *)auStack_df4,1,0); - if ((-1 < iVar1) && ((Status.fd._2_2_ & 1) == 0)) { - bVar5 = true; - } - if (!bVar5) goto LAB_080dd030; - print(); - BuddyIDs[99] = 0; - pcVar2 = TConnection::GetIPAddress(Connection); - iVar6 = TQueryManagerConnection::loginGame - ((TQueryManagerConnection *)QueryManagerConnection.QueryManagerConnectionPool, - AccountID,PlayerName,PlayerPassword,pcVar2,PrivateWorld,false, - GamemasterClient,(ulong *)&Status_1.events,(int *)&CharacterID,Rank + 0x1c, - Title + 0x1c,local_22c,&Sex,(ulong *)(Guild + 0x1c), - (char (*) [30])&Status.events,(uchar *)(BuddyIDs + 99), - (bool *)((int)&NumberOfBuddies + 3)); - switch(iVar6) { - case 0: - // try { // try from 080dd05c to 080dd11d has its CatchHandler @ 080dd590 - _auStack_e0c = TConnection::GetSocket(Connection); - bVar5 = false; - Status_1.fd._0_2_ = 1; - iVar6 = poll((pollfd *)auStack_e0c,1,0); - if ((-1 < iVar6) && ((Status_1.fd._2_2_ & 1) == 0)) { - bVar5 = true; - } - if (!bVar5) { - TQueryManagerConnection::decrementIsOnline - ((TQueryManagerConnection *)QueryManagerConnection.QueryManagerConnectionPool, - Status_1._4_4_); - iVar6 = Status_1._4_4_; - goto LAB_080dd030; - } - if (AccountID == 0) { - error("PerformRegistration: Spieler %s wurde noch keinem Account zugewiesen.\n", - PlayerName); - pcVar2 = - "Character is not assigned to an account.\nPerform this on the Tibia website\nat \"www.tibia.com\"." - ; - } - else { - PlayerName[0x1d] = '\0'; - if (NumberOfBuddies._3_1_ != '\0') { - SendLoginMessage(Connection,0x15, - "Your Premium Account is now activated.\nHave a lot of fun in Tibia." - ,-1); - } - pcVar2 = TConnection::GetIPAddress(Connection); - iVar6 = TConnection::GetSocket(Connection); - Log("game","Spieler %s loggt ein an Socket %d von %s.\n",PlayerName,iVar6,pcVar2); - pcVar2 = (char *)0x1; - pTVar3 = AssignPlayerPoolSlot(Status_1._4_4_,true); - if (pTVar3 != (TPlayerData *)0x0) { - _Var4 = getpid(); - bVar5 = pTVar3->Locked == _Var4; - if ((bVar5) || (pTVar3->AccountID == 0)) { - pTVar3->Sex = CharacterID; - pTVar3->AccountID = AccountID; - strcpy(pTVar3->Name,PlayerName); - *(ulong *)pTVar3->Rights = BuddyIDs[99]; - pTVar3->Rights[4] = '\0'; - pTVar3->Rights[5] = '\0'; - pTVar3->Rights[6] = '\0'; - pTVar3->Rights[7] = '\0'; - pTVar3->Rights[8] = '\0'; - pTVar3->Rights[9] = '\0'; - pTVar3->Rights[10] = '\0'; - pTVar3->Rights[0xb] = '\0'; - strcpy(pTVar3->Guild,Rank + 0x1c); - strcpy(pTVar3->Rank,Title + 0x1c); - pcVar2 = local_22c; - strcpy(pTVar3->Title,pcVar2); - } - if ((bVar5) && (pTVar3->Buddies == 0)) { - pTVar3->Buddies = Sex; - local_e14 = 0; - if (0 < Sex) { - local_e18 = 0; - __dest = pTVar3->BuddyName; - do { - pTVar3->Buddy[local_e14] = *(ulong *)(Guild + local_e14 * 4 + 0x1c); - pcVar2 = BuddyNames[-1] + local_e18 + 0x1a; - strcpy(*__dest,pcVar2); - local_e14 = local_e14 + 1; - local_e18 = local_e18 + 0x1e; - __dest = __dest + 1; - } while (local_e14 < Sex); - } - } - TQueryManagerPoolConnection::~TQueryManagerPoolConnection - ((TQueryManagerPoolConnection *)local_2c,(int)pcVar2); - return pTVar3; - } - // try { // try from 080dd27e to 080dd569 has its CatchHandler @ 080dd590 - error(&DAT_0810c160); - TQueryManagerConnection::decrementIsOnline - ((TQueryManagerConnection *)QueryManagerConnection.QueryManagerConnectionPool, - Status_1._4_4_); - pcVar2 = "There are too many players online.\nPlease try again later."; - } - break; - case 1: - print(); - pcVar2 = - "Character doesn\'t exist.\nCreate a new character on the Tibia website\nat \"www.tibia.com\"." - ; - break; - case 2: - print(); - pcVar2 = "Character doesn\'t exist.\nCreate a new character on the Tibia website."; - break; - case 3: - print(); - pcVar2 = "Character doesn\'t live on this world.\nPlease login on the right world."; - break; - case 4: - print(); - pcVar2 = "This world is private and you have not been invited to play on it."; - break; - default: - pcVar2 = &DAT_0810c4a0; - goto LAB_080dd3a0; - case 6: - pcVar2 = TConnection::GetIPAddress(Connection); - Log("game",&DAT_0810c500,PlayerName,pcVar2); - goto LAB_080dd3d1; - case 7: - pcVar2 = TConnection::GetIPAddress(Connection); - Log("game","Spieler %s blockiert; Login von %s.\n",PlayerName,pcVar2); - pcVar2 = "Account disabled for five minutes. Please wait."; - break; - case 8: - Log("game",&DAT_0810c600,PlayerName); -LAB_080dd3d1: - pcVar2 = "Accountnumber or password is not correct."; - break; - case 9: - pcVar2 = TConnection::GetIPAddress(Connection); - Log("game",&DAT_0810c640,pcVar2,PlayerName); - pcVar2 = "IP address blocked for 30 minutes. Please wait."; - break; - case 10: - print(); - pcVar2 = "Your account is banished."; - break; - case 0xb: - print(); - pcVar2 = "Your character is banished because of his/her name."; - break; - case 0xc: - print(); - pcVar2 = "Your IP address is banished."; - break; - case 0xd: - print(); - pcVar2 = "You may only login with one character\nof your account at the same time."; - break; - case 0xe: - print(); - pcVar2 = "You may only login with a Gamemaster account."; - break; - case 0xf: - Log("game",&DAT_0810c860,AccountID,PlayerName); - pcVar2 = "Login failed due to corrupt data."; - break; - case -1: - goto switchD_080dcfed_caseD_0; - } -LAB_080dd020: - iVar6 = 0x14; - SendLoginMessage(Connection,0x14,pcVar2,-1); -LAB_080dd030: - TQueryManagerPoolConnection::~TQueryManagerPoolConnection - ((TQueryManagerPoolConnection *)local_2c,iVar6); - return (TPlayerData *)0x0; -} - - - -bool HandleLogin(TConnection *Connection) - -{ - TReadBuffer *this; - int *ctx; - TWaitinglistEntry *pTVar1; - uchar Command; - uchar uVar2; - bool bVar3; - bool bVar4; - ushort w; - ushort w_00; - ulong AccountID_00; - int iVar5; - TPlayerData *Slot; - __pid_t _Var6; - pid_t pVar7; - bool FreeAccount_00; - bool Newbie_00; - int WaitingTime; - TPlayerData *PlayerData; - int Type; - TQueryManagerConnectionPool *CharacterID; - uchar *out; - char *pcVar8; - size_t *in_stack_fffffed0; - uchar *in_stack_fffffed4; - size_t in_stack_fffffed8; - bool ReadOnly; - ulong AccountID; - bool GamemasterClient; - ushort TerminalVersion; - ushort TerminalType; - bool local_102; - bool local_101; - bool Newbie; - ulong uStack_100; - bool FreeAccount; - ulong NextTry; - TWriteBuffer WriteBuffer; - uchar AssymmetricData [128]; - char PlayerPassword [31]; - char PlayerName [31]; - TReadBuffer Buffer; - - this = (TReadBuffer *)(PlayerName + 0x1c); - TReadBuffer::TReadBuffer(this,Connection->InData + 2,0x7fe); - // try { // try from 080dd5e8 to 080dd5ec has its CatchHandler @ 080ddd00 - uVar2 = TReadBuffer::readByte(this); - if (uVar2 == '\n') { - out = (uchar *)0x80; - ctx = &WriteBuffer.Position; - // try { // try from 080dd635 to 080dd645 has its CatchHandler @ 080ddde8 - TReadBuffer::readBytes(this,(uchar *)ctx,0x80); - Semaphore::down(&RSAMutex); - // try { // try from 080dd651 to 080dd655 has its CatchHandler @ 080ddd3f - TRSAPrivateKey::decrypt - (&PrivateKey,(EVP_PKEY_CTX *)ctx,out,in_stack_fffffed0,in_stack_fffffed4, - in_stack_fffffed8); - // try { // try from 080dd65d to 080dd74c has its CatchHandler @ 080ddde8 - Semaphore::up(&RSAMutex); - TReadBuffer::TReadBuffer((TReadBuffer *)&NextTry,(uchar *)ctx,0x80); - TReadBuffer::readByte((TReadBuffer *)&NextTry); - TXTEASymmetricKey::init - (&Connection->SymmetricKey,(EVP_PKEY_CTX *)((int)ctx + WriteBuffer.Size)); - TReadBuffer::skip((TReadBuffer *)&NextTry,0x10); - w = TReadBuffer::readWord((TReadBuffer *)&NextTry); - w_00 = TReadBuffer::readWord((TReadBuffer *)&NextTry); - uVar2 = TReadBuffer::readByte((TReadBuffer *)&NextTry); - AccountID_00 = TReadBuffer::readQuad((TReadBuffer *)&NextTry); - pcVar8 = PlayerPassword + 0x1c; - TReadStream::readString((TReadStream *)&NextTry,pcVar8,0x1e); - TReadStream::readString((TReadStream *)&NextTry,(char *)(AssymmetricData + 0x7c),0x1e); - if (PlayerPassword[0x1c] == '\0') { - pcVar8 = "You must enter a character name."; - } - else if ((w < 3) && (TERMINALVERSION[w] <= (int)(uint)w_00)) { - bVar3 = GameRunning(); - if (bVar3) { - bVar3 = GameStarting(); - if (bVar3) { - pcVar8 = "The game is just starting.\nPlease try again later."; - } - else { - bVar3 = GameEnding(); - if (!bVar3) { - do { - Semaphore::down(&CommunicationThreadMutex); - for (pTVar1 = WaitinglistHead; pTVar1 != (TWaitinglistEntry *)0x0; - pTVar1 = pTVar1->Next) { - iVar5 = stricmp(pcVar8,pTVar1->Name,-1); - if (iVar5 == 0) { - uStack_100 = pTVar1->NextTry; - local_101 = pTVar1->FreeAccount; - local_102 = pTVar1->Newbie; - Semaphore::up(&CommunicationThreadMutex); - bVar3 = true; - goto LAB_080dd827; - } - } - Semaphore::up(&CommunicationThreadMutex); - bVar3 = false; -LAB_080dd827: - if (!bVar3) { - print(); - Slot = PerformRegistration(Connection,pcVar8,AccountID_00, - (char *)(AssymmetricData + 0x7c), - uVar2 != '\0'); - if (Slot == (TPlayerData *)0x0) { - return false; - } - _Var6 = getpid(); - bVar3 = Slot->Locked != _Var6; - FreeAccount_00 = (bool)((Slot->Rights[0] ^ 1) & 1); - Newbie_00 = false; - if ((Slot->Profession == 0) && ((Slot->Rights[8] & 0x40) == 0)) { - Newbie_00 = true; - } - if ((FreeAccount_00 == false) || - ((MaxPlayers != PremiumPlayerBuffer && - ((Newbie_00 == false || (MaxNewbies != PremiumNewbieBuffer)))))) - { - bVar4 = IsPlayerOnline(pcVar8); - if ((bVar4) || - (iVar5 = CheckWaitingTime(pcVar8,Connection,FreeAccount_00, - Newbie_00), iVar5 < 1)) - goto LAB_080dd929; - InsertWaitinglistEntry - (pcVar8,iVar5 + RoundNr,FreeAccount_00,Newbie_00); - CharacterID = &QueryManagerConnectionPool; - TQueryManagerPoolConnection::TQueryManagerPoolConnection - ((TQueryManagerPoolConnection *)&NextTry, - &QueryManagerConnectionPool); - if (WriteBuffer.super_TWriteStream._vptr_TWriteStream == - (_func_int_varargs **)0x0) { - error( - "HandleLogin: Kann Verbindung zum Query-Manager nicht herstellen.\n" - ); - } - else { - CharacterID = (TQueryManagerConnectionPool *) - Slot->CharacterID; - // try { // try from 080ddbdb to 080ddbf0 has its CatchHandler @ 080dde0a - TQueryManagerConnection::decrementIsOnline - ((TQueryManagerConnection *) - WriteBuffer.super_TWriteStream._vptr_TWriteStream - ,(ulong)CharacterID); - } - if (bVar3) { - DecreasePlayerPoolSlotSticky(Slot); - } - else { - // try { // try from 080ddc07 to 080ddc19 has its CatchHandler @ 080dde0a - ReleasePlayerPoolSlot(Slot); - } - } - else { - SendLoginMessage(Connection,0x14, - - "Only players with premium accounts\nare allowed to enter this world." - ,-1); - CharacterID = &QueryManagerConnectionPool; - TQueryManagerPoolConnection::TQueryManagerPoolConnection - ((TQueryManagerPoolConnection *)&NextTry, - &QueryManagerConnectionPool); - if (WriteBuffer.super_TWriteStream._vptr_TWriteStream == - (_func_int_varargs **)0x0) { - error( - "HandleLogin: Kann Verbindung zum Query-Manager nicht herstellen.\n" - ); - } - else { - CharacterID = (TQueryManagerConnectionPool *) - Slot->CharacterID; - // try { // try from 080ddc65 to 080ddc9e has its CatchHandler @ 080dddf5 - TQueryManagerConnection::decrementIsOnline - ((TQueryManagerConnection *) - WriteBuffer.super_TWriteStream._vptr_TWriteStream - ,(ulong)CharacterID); - } - if (bVar3) { - DecreasePlayerPoolSlotSticky(Slot); - } - else { - ReleasePlayerPoolSlot(Slot); - } - } - TQueryManagerPoolConnection::~TQueryManagerPoolConnection - ((TQueryManagerPoolConnection *)&NextTry,(int)CharacterID) - ; - return false; - } - print(); - iVar5 = uStack_100 - RoundNr; - if (0 < iVar5) { - Log("queue",&DAT_0810ca20,pcVar8,iVar5); - pcVar8 = "It\'s not your turn yet."; - Type = 0x16; - goto LAB_080dd78e; - } - if (-0x3d < iVar5) { - iVar5 = CheckWaitingTime(pcVar8,Connection,local_101,local_102); - if (0 < iVar5) { - InsertWaitinglistEntry - (pcVar8,iVar5 + RoundNr,local_101,local_102); - return false; - } - DeleteWaitinglistEntry(pcVar8); - Slot = PerformRegistration(Connection,pcVar8,AccountID_00, - (char *)(AssymmetricData + 0x7c), - uVar2 != '\0'); - if (Slot == (TPlayerData *)0x0) { - return false; - } - _Var6 = getpid(); - bVar3 = Slot->Locked != _Var6; -LAB_080dd929: - if (!bVar3) { - IncreasePlayerPoolSlotSticky(Slot); - ReleasePlayerPoolSlot(Slot); - } - TWriteBuffer::TWriteBuffer - ((TWriteBuffer *)&NextTry,Connection->InData + 2,0x7fe); - // try { // try from 080dd967 to 080dd9af has its CatchHandler @ 080dde17 - TWriteBuffer::writeByte((TWriteBuffer *)&NextTry,'\v'); - TWriteBuffer::writeWord((TWriteBuffer *)&NextTry,w); - TWriteBuffer::writeWord((TWriteBuffer *)&NextTry,w_00); - TWriteBuffer::writeQuad((TWriteBuffer *)&NextTry,Slot->CharacterID); - Connection->NextToSend = 0; - Connection->NextToCommit = 0; - Connection->InDataSize = WriteBuffer.Size; - Connection->NextToWrite = 0; - TConnection::Login(Connection); - bVar3 = GameRunning(); - if (bVar3) { - Connection->WaitingForACK = true; - pVar7 = GetGameThreadPID(); - iVar5 = kill(pVar7,10); - if (iVar5 != 0) { - pVar7 = GetGameThreadPID(); - error("CallGameThread: Can\'t send SIGUSR1 to pid %d\n", - pVar7); - SendLoginMessage(Connection,0x14, - - "The server is not online.\nPlease try again later." - ,-1); - return false; - } - } - return true; - } - Log("queue",&DAT_0810c9e0,pcVar8,-iVar5); - DeleteWaitinglistEntry(pcVar8); - } while( true ); - } - pcVar8 = "The game is just going down.\nPlease try again later."; - } - } - else { - pcVar8 = "The server is not online.\nPlease try again later."; - } - } - else { - pcVar8 = - "Your terminal version is too old.\nPlease get a new version at\nhttp://www.tibia.com."; - } - iVar5 = -1; - Type = 0x14; -LAB_080dd78e: - SendLoginMessage(Connection,Type,pcVar8,iVar5); - } - else { - print(); - } - return false; -} - - - -// WARNING: Variable defined which should be unmapped: Help - -bool ReceiveCommand(TConnection *Connection) - -{ - uint uVar1; - bool bVar2; - int n; - int iVar3; - uchar *puVar4; - EVP_PKEY_CTX *ctx; - pid_t pVar5; - ssize_t sVar6; - int Offset; - int Count; - uchar *Size; - uchar *out; - size_t *in_stack_ffffffe0; - uchar *in_stack_ffffffe4; - size_t in_stack_ffffffe8; - byte local_12; - byte local_11; - uchar Help [2]; - - if (Connection == (TConnection *)0x0) { - error("ReceiveCommand: Connection ist NULL.\n"); -LAB_080de0d3: - bVar2 = false; - } - else { - do { - do { - while( true ) { - iVar3 = ReadFromSocket(Connection,&local_12,2); - if (iVar3 == 0) { - return false; - } - if (iVar3 < 0) { - return true; - } - if (iVar3 < 2) { - Semaphore::down(&CommunicationThreadMutex); - TotalRecv = TotalRecv + 0x31; - Semaphore::up(&CommunicationThreadMutex); - TConnection::GetSocket(Connection); - print(); - goto LAB_080de003; - } - Size = (uchar *)((uint)local_11 * 0x100 + (uint)local_12); - Connection->InDataSize = (int)Size; - if (((uchar *)0x7fd < Size) || (Size == (uchar *)0x0)) { - TConnection::GetSocket(Connection); - print(); - if (Size != (uchar *)0x0) { - do { - Size = Size + -0x800; - iVar3 = TConnection::GetSocket(Connection); - sVar6 = read(iVar3,Connection,0x800); - Semaphore::down(&CommunicationThreadMutex); - TotalRecv = TotalRecv + sVar6 + 0x30; - Semaphore::up(&CommunicationThreadMutex); - } while (0 < (int)Size); - } - goto LAB_080de003; - } - if (Connection->State == CONNECTION_CONNECTED) break; - out = Size; - puVar4 = (uchar *)ReadFromSocket(Connection,Connection->InData,(int)Size); - if ((int)puVar4 < 0) { -LAB_080de0b0: - SendLoginMessage(Connection,0x14,"Internal error, closing connection.",-1); - goto LAB_080de0d3; - } - Semaphore::down(&CommunicationThreadMutex); - TotalRecv = (int)puVar4 + TotalRecv + 0x30; - Semaphore::up(&CommunicationThreadMutex); - if (puVar4 == Size) { - if (((uint)Size & 7) == 0) { - iVar3 = 0; - if (Size != (uchar *)0x0) { - do { - ctx = (EVP_PKEY_CTX *)(Connection->InData + iVar3); - iVar3 = iVar3 + 8; - TXTEASymmetricKey::decrypt - (&Connection->SymmetricKey,ctx,out,in_stack_ffffffe0, - in_stack_ffffffe4,in_stack_ffffffe8); - } while (iVar3 < (int)Size); - } - uVar1 = (uint)Connection->InData[1] * 0x100 + - (uint)Connection->InData[0]; - Connection->InDataSize = uVar1; - if ((uVar1 < 0x7fe) && (uVar1 != 0)) goto LAB_080ddfc8; - in_stack_ffffffe0 = (size_t *)TConnection::GetSocket(Connection); - } - else { - in_stack_ffffffe0 = (size_t *)TConnection::GetName(Connection); - } - print(); - } - } - iVar3 = ReadFromSocket(Connection,Connection->InData + 2,(int)Size); - if (iVar3 < 0) goto LAB_080de0b0; - Semaphore::down(&CommunicationThreadMutex); - TotalRecv = TotalRecv + iVar3 + 0x30; - Semaphore::up(&CommunicationThreadMutex); - } while (iVar3 != Connection->InDataSize); -LAB_080ddfc8: - if (Connection->State == CONNECTION_CONNECTED) { - alarm(0); - bVar2 = HandleLogin(Connection); - } - else { - bVar2 = GameRunning(); - if (bVar2) { - Connection->WaitingForACK = true; - pVar5 = GetGameThreadPID(); - iVar3 = kill(pVar5,10); - if (iVar3 != 0) { - pVar5 = GetGameThreadPID(); - error("CallGameThread: Can\'t send SIGUSR1 to pid %d\n",pVar5); - in_stack_ffffffe0 = (size_t *)0xffffffff; - SendLoginMessage(Connection,0x14, - "The server is not online.\nPlease try again later.",-1); - bVar2 = false; - goto LAB_080ddfe6; - } - } - bVar2 = true; - } -LAB_080ddfe6: - if (bVar2 == false) { - return false; - } - } while (Connection->WaitingForACK == false); - Connection->SigIOPending = true; -LAB_080de003: - bVar2 = true; - } - return bVar2; -} - - - // WARNING: Unknown calling convention -- yet parameter storage is locked void IncrementActiveConnections(void) -- cgit v1.2.3