Skip to content

Commit

Permalink
Onlinectr v1021 (#201)
Browse files Browse the repository at this point in the history
* room player counts dynamically update, items in itemless rooms mitigation.

* separated LPL into the helper file, fixed no updating when in post-game lobby.

* fixed clients not being updated in other specific circumstances.

* add banlist feature

* "join room queue" feature and a couple of ll bugfixes

* update client/server version special casing compatibility

* fixed the underlying "player count not updating" bug

* include faradise's bubble/bomb fix, include SpookerI's function type fix (linux compile)

* change a client log message
  • Loading branch information
TheUbMunster authored Dec 7, 2024
1 parent e001a2e commit 9530eb4
Show file tree
Hide file tree
Showing 7 changed files with 449 additions and 152 deletions.
6 changes: 3 additions & 3 deletions decompile/General/AltMods/OnlineCTR/global.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef ONLINE_GLOBAL_H
#define ONLINE_GLOBAL_H

#define VERSION 1020
#define VERSION 1021
//#define ONLINE_BETA_MODE

#ifndef WINDOWS_INCLUDE
Expand Down Expand Up @@ -162,10 +162,10 @@ struct OnlineCTR
// Last windowsClientSync counter
char lastWindowsClientSync;

char desiredFPS;

// when to start the client.exe loop
int readyToSend;

int autoRetryJoinRoomIndex;
};

STATIC_ASSERT2(sizeof(struct OnlineCTR) <= 0x400, "Size of OnlineCTR must be lte 1kb");
Expand Down
19 changes: 17 additions & 2 deletions decompile/General/AltMods/OnlineCTR/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,28 @@ void NewPage_ServerRoom()

int numRooms = GetNumRoom();

int buttons = sdata->gGamepads->gamepad[0].buttonsTapped;

for(i = 0; i < 8; i++)
{
// unlock row if...
if(8*pn+i < numRooms)
if(octr->clientCount[8*pn+i] <= 7)
if (8 * pn + i < numRooms)
{
if (octr->clientCount[8 * pn + i] <= 7)
{
menuRows[i].stringIndex &= 0x7FFF;
}
else if ((buttons & BTN_CROSS) && (menu.rowSelected == i))
{
int rn = i + (pn * 8);
if (octr->autoRetryJoinRoomIndex == rn)
octr->autoRetryJoinRoomIndex = -1;
else
octr->autoRetryJoinRoomIndex = rn;
}
}
}

}

void MenuWrites_ServerRoom()
Expand Down
87 changes: 64 additions & 23 deletions decompile/General/AltMods/OnlineCTR/states.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ bool initString = true;

void StatePS1_Launch_PickServer()
{
octr->autoRetryJoinRoomIndex = -1;
if (initString)
{
strcpy(sdata->lngStrings[0x4e], "OnlineCTR");
Expand Down Expand Up @@ -97,6 +98,30 @@ void StatePS1_Launch_PickRoom()
text,
menu.posX_curr,0xb8,
FONT_SMALL,JUSTIFY_CENTER|PAPU_YELLOW);

if (octr->autoRetryJoinRoomIndex != -1)
{
char* wtj = "Waiting to join ->";
int lineInd = octr->autoRetryJoinRoomIndex % 8;
int pageNum = octr->autoRetryJoinRoomIndex / 8;
if (pageNum == octr->PageNumber)
DecalFont_DrawLine(wtj, 0xE0, 0x6b + (lineInd * 8), FONT_SMALL, JUSTIFY_CENTER | TINY_GREEN);
if (octr->clientCount[octr->autoRetryJoinRoomIndex] <= 7)
{
octr->serverRoom = octr->autoRetryJoinRoomIndex;
octr->serverLockIn2 = 1;
octr->autoRetryJoinRoomIndex = -1;
//0 = cursor move noise
//1 = cursor select noise
//2 = triangle noise
//3 = Ding!
//4 = different ding!
//5 = womp
//6 = slammed into wall sfx
//...
DECOMP_OtherFX_Play(3, 1); //play SFX to notify user
}
}
}

void StatePS1_Launch_Error()
Expand Down Expand Up @@ -394,31 +419,47 @@ void StatePS1_Game_StartRace()
octr->Shoot[i].boolNow = 0;

struct Driver* d = sdata->gGT->drivers[i];

if(octr->Shoot[i].boolJuiced)
d->numWumpas = 10;

d->heldItemID = octr->Shoot[i].Weapon;

// copy/paste from ShootOnCirclePress
int weapon;
weapon = d->heldItemID;

// Missiles and Bombs share code,
// Change Bomb1x, Bomb3x, Missile3x, to Missile1x
if(
(weapon == 1) ||
(weapon == 10) ||
(weapon == 11)
)
if (d->instBombThrow != 0)
{
weapon = 2;
// Detonate the bomb
struct TrackerWeapon* bomb = (struct TrackerWeapon*)d->instBombThrow->thread->object;
bomb->flags |= 2;
d->instBombThrow = NULL;
}
else if (d->instBubbleHold != 0)
{
// Shoot the shield
struct Shield* shield = (struct Shield*)d->instBubbleHold->thread->object;
shield->flags |= 2;
d->instBubbleHold = NULL;
}
else
{
if (octr->Shoot[i].boolJuiced)
d->numWumpas = 10;

d->heldItemID = octr->Shoot[i].Weapon;

// copy/paste from ShootOnCirclePress
int weapon;
weapon = d->heldItemID;

// Missiles and Bombs share code,
// Change Bomb1x, Bomb3x, Missile3x, to Missile1x
if (
(weapon == 1) ||
(weapon == 10) ||
(weapon == 11)
)
{
weapon = 2;
}

DECOMP_VehPickupItem_ShootNow(
d,
weapon,
octr->Shoot[i].flags);
}

DECOMP_VehPickupItem_ShootNow(
d,
weapon,
octr->Shoot[i].flags);
}
}
}
Expand Down
13 changes: 11 additions & 2 deletions decompile/General/Vehicle/VehPhysProc_Driving_PhysLinear.c
Original file line number Diff line number Diff line change
Expand Up @@ -513,13 +513,19 @@ void DECOMP_VehPhysProc_Driving_PhysLinear(struct Thread* thread, struct Driver*
(driver->instTntRecv == 0)
)
{
#if defined(USE_ONLINE)
int rn = octr->serverRoom;
#endif
// If there is a Bomb Pointer
if (driver->instBombThrow != 0)
{
// Detonate the bomb
bomb = (struct TrackerWeapon*)driver->instBombThrow->thread->object;
bomb->flags |= 2;
driver->instBombThrow = 0;
driver->instBombThrow = NULL;
#if defined(USE_ONLINE)
if (ROOM_IS_ITEMS(rn) && driver->driverID == 0) octr->Shoot[0].boolNow = 1;
#endif
goto CheckJumpButtons;
}

Expand All @@ -529,7 +535,10 @@ void DECOMP_VehPhysProc_Driving_PhysLinear(struct Thread* thread, struct Driver*
// Shoot the bubble
shield = (struct Shield*)driver->instBubbleHold->thread->object;
shield->flags |= 2;
driver->instBubbleHold = 0;
driver->instBubbleHold = NULL;
#if defined(USE_ONLINE)
if (ROOM_IS_ITEMS(rn) && driver->driverID == 0) octr->Shoot[0].boolNow = 1;
#endif
goto CheckJumpButtons;
}

Expand Down
9 changes: 6 additions & 3 deletions mods/Windows/OnlineCTR/Network_PC/Client/CL_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void ProcessReceiveEvent(ENetPacket* packet)
octr->ver_pc = VERSION;
octr->ver_server = r->version;

if (!(r->version == 1019 && VERSION == 1020)) //special case, v1019 servers are fully compatible with v1020 clients.
if (!(r->version == 1019 && VERSION == 1020) && !(r->version == 1019 && VERSION == 1021) && !(r->version == 1020 && VERSION == 1021)) //special case, certain servers are compatible with certain other client versions.
if (r->version != VERSION)
{
octr->CurrState = LAUNCH_ERROR;
Expand Down Expand Up @@ -496,6 +496,7 @@ void DisconSELECT()
enet_peer_disconnect_now(serverPeer, 0);
serverPeer = 0;

octr->autoRetryJoinRoomIndex = -1;
// to go the lobby browser
octr->CurrState = -1;
return;
Expand Down Expand Up @@ -567,7 +568,7 @@ void StatePC_Launch_PickServer()
if (serverPeer != 0)
{
//when it dc's it ends up here. Either this is causing the enet dc or the client is bugged to call this function again when it shouldn't
printf("NON-`null` enet server peer during server connection (case 1), disconnecting from old server...\n");
printf("Disconnecting from old server...\n");
enet_peer_disconnect_now(serverPeer, 0);
serverPeer = 0;
}
Expand Down Expand Up @@ -805,7 +806,7 @@ int countFrame = 0;
void StatePC_Launch_PickRoom()
{
countFrame++;
if (countFrame == octr->desiredFPS)
if (countFrame == 30 * 5) //just in case server's tracking & updating is flawed
{
countFrame = 0;

Expand Down Expand Up @@ -834,6 +835,7 @@ void StatePC_Launch_PickRoom()
CG_MessageRoom mr;
mr.type = CG_JOINROOM;
mr.room = octr->serverRoom;
octr->autoRetryJoinRoomIndex = -1;

sendToHostReliable(&mr, sizeof(CG_MessageRoom));
}
Expand Down Expand Up @@ -1255,6 +1257,7 @@ int main(int argc, char *argv[])
}

octr = (OnlineCTR*)&pBuf[0x8000C000 & 0xffffff];
octr->autoRetryJoinRoomIndex = -1;

// initialize enet
if (enet_initialize() != 0)
Expand Down
123 changes: 123 additions & 0 deletions mods/Windows/OnlineCTR/Network_PC/Server/SV_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,126 @@ int GetWeekDay()

return buffer[0] - '0';
}

#include "malloc.h"

typedef ENetPeer;
struct LoosePeerList;
struct LoosePeerList {
ENetPeer* peer;
struct LoosePeerList* next;
};

struct LoosePeerList* lplHead = NULL;

void AddPeerLPL(ENetPeer* peer)
{
if (lplHead == NULL)
{
lplHead = malloc(sizeof(struct LoosePeerList));
lplHead->next = NULL;
lplHead->peer = peer;
}
else
{
struct LoosePeerList* c = lplHead;
while (c->next != NULL)
c = c->next;
c->next = malloc(sizeof(struct LoosePeerList));
c->next->next = NULL;
c->next->peer = peer;
}
}

int RemovePeerLPL(ENetPeer* peer)
{
int didFree = 0;
struct LoosePeerList* c = lplHead, * prev = NULL;
while (c != NULL)
{
if (c->peer == peer)
{
if (prev == NULL)
{
struct LoosePeerList* toFree = c;

lplHead = c->next;
c = c->next;

free(toFree);
didFree |= 1;

}
else
{

struct LoosePeerList* toFree = c;

prev->next = c->next;
c = c->next;

free(toFree);
didFree |= 1;
}
}
else
{
//i++
prev = c;
c = c->next;
}
}
return didFree;
}

int ForeachPeerLPL(void (*lambda)(ENetPeer*))
{
int count = 0;
struct LoosePeerList* c = lplHead;
while (c != NULL)
{
count++;
(*lambda)(c->peer);
c = c->next;
}
return count;
}

struct IPBanL;
struct IPBanL {
unsigned int ip;
struct IPBanL* next;
};

struct IPBanL* ipBanLHead = NULL;

void AddIPBanL(unsigned int IP)
{
if (ipBanLHead == NULL)
{
ipBanLHead = malloc(sizeof(struct IPBanL));
ipBanLHead->next = NULL;
ipBanLHead->ip = IP;
}
else
{
struct IPBanL* c = ipBanLHead;
while (c->next != NULL)
c = c->next;
c->next = malloc(sizeof(struct IPBanL));
c->next->next = NULL;
c->next->ip = IP;
}
}

int AnyMatchIPBanL(unsigned int IP)
{
int match = 0;
struct IPBanL* c = ipBanLHead;
while (c != NULL)
{
match |= c->ip == IP;
c = c->next;
}
return match;
}
Loading

0 comments on commit 9530eb4

Please sign in to comment.