Skip to content

Commit 8255543

Browse files
committed
Refactor costume handling: replaced CostumeSend with CostumeInf, updated packet handling, and improved string safety in CostumeInf constructor. Adjusted Makefile for debugging settings. Added Makefile to .gitignore.
1 parent cddd959 commit 8255543

8 files changed

Lines changed: 36 additions & 42 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ Custom Stage Builds/**
1010

1111
compile_commands.json
1212

13-
Ultimate_SMO_Compiler.bat
13+
Ultimate_SMO_Compiler.bat
14+
Makefile

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ SMOVER ?= 100
77
BUILDVER ?= 101
88
BUILDVERSTR ?= 1.3.0
99
IP ?= 192.168.0.9 # ftp server ip (usually is switch's local IP)
10-
DEBUGLOG ?= 0 # defaults to disable debug logger
11-
SERVERIP ?= 192.168.0.58 # put debug logger server IP here
10+
DEBUGLOG ?= 1 # defaults to disable debug logger
11+
SERVERIP ?= 192.168.178.37 # put debug logger server IP here
1212
ISEMU ?= 0 # set to 1 to compile for emulators
1313

1414
PROJNAME ?= StarlightBase

include/packets/CostumeInf.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@
22

33
#include "Packet.h"
44

5+
// Structure for sending/receiving costume information (Mod <-> Server)
56
struct PACKED CostumeInf : Packet {
6-
CostumeInf() : Packet() {this->mType = PacketType::COSTUMEINF; mPacketSize = sizeof(CostumeInf) - sizeof(Packet);};
7+
CostumeInf() : Packet() {
8+
this->mType = PacketType::COSTUMEINF;
9+
mPacketSize = sizeof(CostumeInf) - sizeof(Packet);
10+
}
711
CostumeInf(const char* body, const char* cap) : Packet() {
812
this->mType = PacketType::COSTUMEINF;
913
mPacketSize = sizeof(CostumeInf) - sizeof(Packet);
10-
strcpy(bodyModel, body);
11-
strcpy(capModel, cap);
14+
if (body)
15+
strncpy(bodyModel, body, COSTUMEBUFSIZE - 1);
16+
bodyModel[COSTUMEBUFSIZE - 1] = '\0';
17+
if (cap)
18+
strncpy(capModel, cap, COSTUMEBUFSIZE - 1);
19+
capModel[COSTUMEBUFSIZE - 1] = '\0';
1220
}
1321
char bodyModel[COSTUMEBUFSIZE] = {};
1422
char capModel[COSTUMEBUFSIZE] = {};

include/packets/CostumeSend.hpp

Lines changed: 0 additions & 18 deletions
This file was deleted.

include/packets/Packet.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ enum PacketType : short {
2828
CMD, // = 12
2929
EXTRA, // = 15
3030
HEALTH_COINS, // = 16
31-
COSTUMESEND, // = 17
3231
End // end of enum for bounds checking
3332
};
3433

@@ -48,8 +47,7 @@ USED static const char *packetNames[] = {
4847
"Change Stage",
4948
"Server Command",
5049
"Extras Packets (infCapDives & Noclip)",
51-
"Health and Coins",
52-
"Send Costume"
50+
"Health and Coins"
5351
};
5452

5553
enum SenderType {

include/server/Client.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
#include "packets/PlayerInfPacket.h"
7676
#include "packets/ShineCollect.h"
7777
#include "packets/Extras.hpp"
78-
#include "packets/CostumeSend.hpp"
7978

8079

8180
#include "puppets/PuppetInfo.h"
@@ -242,7 +241,7 @@ class Client {
242241
void updateCaptureInfo(CaptureInf* packet);
243242
void sendToStage(ChangeStagePacket* packet);
244243
void handleExtrasPacket(ExtrasPacket* curPacket);
245-
void handleCostumSend(CoustumeSend* curPacket);
244+
void handleCostumSend(CostumeInf* curPacket);
246245

247246
void disconnectPlayer(PlayerDC *packet);
248247

source/main.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141

4242
#include "packets/Extras.h"
4343
#include "packets/Extras.hpp"
44-
#include "packets/CostumeSend.hpp"
4544
#include "server/ExtrasCode.hpp"
4645

4746
static int pInfSendTimer = 0;
@@ -120,10 +119,16 @@ void updatePlayerInfo(GameDataHolderAccessor holder, PlayerActorBase* playerBase
120119

121120
pInfSendTimer = 0;
122121
}
122+
auto hakoniwaPlayer = static_cast<PlayerActorHakoniwa*>(playerBase);
123123

124-
handleNoclip(static_cast<PlayerActorHakoniwa*>(playerBase), gNoclip, isYukimaru);
125-
handleInfiniteCapBounce(static_cast<PlayerActorHakoniwa*>(playerBase), gInfiniteCapBounce);
126-
setOutfit(static_cast<PlayerActorHakoniwa*>(playerBase),BodyName, CapName);
124+
handleNoclip(hakoniwaPlayer, gNoclip, isYukimaru);
125+
handleInfiniteCapBounce(hakoniwaPlayer, gInfiniteCapBounce);
126+
/*
127+
if (hakoniwaPlayer && BodyName && CapName) {
128+
setOutfit(hakoniwaPlayer, BodyName, CapName);
129+
} else {
130+
Logger::log("[ERROR] setOutfit: Nullpointer! player=%p, BodyName=%p, CapName=%p\n", hakoniwaPlayer, BodyName, CapName);
131+
}*/
127132

128133
}
129134

source/server/Client.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "packets/Packet.h"
88
#include "packets/Extras.h"
99
#include "packets/Extras.hpp"
10+
#include "packets/CostumeInf.h"
1011

1112
#include "server/hns/HideAndSeekMode.hpp"
1213
#include "layouts/CustomMsg.h"
@@ -391,8 +392,9 @@ void Client::readFunc() {
391392
case PacketType::EXTRA:
392393
handleExtrasPacket((ExtrasPacket*)curPacket);
393394
break;
394-
case PacketType::COSTUMESEND:
395-
handleCostumSend((CoustumeSend*)curPacket);
395+
case PacketType::COSTUMEINF:
396+
handleCostumSend((CostumeInf*)curPacket);
397+
updateCostumeInfo((CostumeInf*)curPacket);
396398
break;
397399
// Send relevant info packets when another client is connected
398400

@@ -407,9 +409,6 @@ void Client::readFunc() {
407409
if (lastCostumeInfPacket.mUserID == mUserID)
408410
mSocket->send(&lastCostumeInfPacket);
409411

410-
break;
411-
case PacketType::COSTUMEINF:
412-
updateCostumeInfo((CostumeInf*)curPacket);
413412
break;
414413
case PacketType::SHINECOLL:
415414
updateShineInfo((ShineCollect*)curPacket);
@@ -900,7 +899,9 @@ void Client::updatePlayerConnect(PlayerConnect* packet) {
900899
* @param packet
901900
*/
902901
void Client::updateGameInfo(GameInf *packet) {
903-
902+
Logger::log("Received GameInfo packet: size=%zu, type=%d, scenarioNo=%d, stageName=%s, is2D=%d\n",
903+
sizeof(GameInf), packet->mType, packet->scenarioNo, packet->stageName, packet->is2D);
904+
904905
PuppetInfo* curInfo = findPuppetInfo(packet->mUserID, false);
905906

906907
if (!curInfo) {
@@ -965,7 +966,7 @@ void Client::handleExtrasPacket(ExtrasPacket* curPacket) {
965966
*
966967
* @param Packet
967968
*/
968-
void Client::handleCostumSend(CoustumeSend* curPacket) {
969+
void Client::handleCostumSend(CostumeInf* curPacket) {
969970
if (!curPacket) {
970971
Logger::log("[ERROR] handleCostumSend: Received null packet\n");
971972
return;
@@ -976,8 +977,8 @@ void Client::handleCostumSend(CoustumeSend* curPacket) {
976977
extern const char* CapName;
977978

978979
// Set the global costume variables
979-
BodyName = curPacket->BodyName;
980-
CapName = curPacket->CapName;
980+
BodyName = curPacket->bodyModel;
981+
CapName = curPacket->capModel;
981982

982983
Logger::log("[DEBUG] handleCostumSend: Received costume - Body: %s, Cap: %s\n",
983984
BodyName ? BodyName : "null", CapName ? CapName : "null");

0 commit comments

Comments
 (0)