Skip to content

Commit

Permalink
Mark PXO source codes with statics.
Browse files Browse the repository at this point in the history
  • Loading branch information
MaddTheSane committed Jun 4, 2024
1 parent 25f1729 commit 414d521
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 140 deletions.
91 changes: 51 additions & 40 deletions netcon/mtclient/chat_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,43 +57,54 @@ typedef void (*Debug_ConsolePrintf_fp)(int n, const char *format, ...);
extern Debug_ConsolePrintf_fp DLLDebug_ConsolePrintf;
#define MAXCHATBUFFER 500

SOCKET Chatsock;
SOCKADDR_IN Chataddr;
int Socket_connecting = 0;
char Nick_name[33];
char Orignial_nick_name[33];
int Nick_variety = 0;
char szChat_channel[33] = "";
char Input_chat_buffer[MAXCHATBUFFER] = "";
char Chat_tracker_id[33];
char Getting_user_channel_info_for[33] = "";
char Getting_user_tracker_info_for[33] = "";
int Getting_user_channel_error = 0;
int Getting_user_tracker_error = 0;
char User_req_tracker_id[100] = ""; // These are oversized for saftey
char User_req_channel[100] = "";
char *User_list = nullptr;
char *Chan_list = nullptr;
int Socket_connected = 0;
int Chat_server_connected = 0;
int Joining_channel = 0;
int Joined_channel = 0;
int GettingChannelList = 0;
int GettingUserTID = 0;
int GettingUserChannel = 0;

Chat_user *Firstuser, *Curruser;
Chat_command *Firstcommand, *Currcommand;
Chat_channel *Firstchannel, *Currchannel;
static const char *ChatGetString();
static const char *GetWordNum(int num, const char *l_String);
static char *ParseIRCMessage(const char *Line, int iMode);
static int AddChatUser(const char *nickname);
static int RemoveChatUser(char *nickname);
static void RemoveAllChatUsers();
static void AddChatCommandToQueue(int command, const void *data, int len);
static void FlushChatCommandQueue();
static void AddChannel(char *channel, uint16_t numusers, char *topic);
static void FlushChannelList();

static SOCKET Chatsock;
static SOCKADDR_IN Chataddr;
static int Socket_connecting = 0;
static char Nick_name[33];
static char Orignial_nick_name[33];
static int Nick_variety = 0;
static char szChat_channel[33] = "";
static char Input_chat_buffer[MAXCHATBUFFER] = "";
static char Chat_tracker_id[33];
static char Getting_user_channel_info_for[33] = "";
static char Getting_user_tracker_info_for[33] = "";
static int Getting_user_channel_error = 0;
static int Getting_user_tracker_error = 0;
static char User_req_tracker_id[100] = ""; // These are oversized for saftey
static char User_req_channel[100] = "";
static char *User_list = nullptr;
static char *Chan_list = nullptr;
static int Socket_connected = 0;
static int Chat_server_connected = 0;
static int Joining_channel = 0;
static int Joined_channel = 0;
static int GettingChannelList = 0;
static int GettingUserTID = 0;
static int GettingUserChannel = 0;

static Chat_user *Firstuser, *Curruser;
static Chat_command *Firstcommand, *Currcommand;
static Chat_channel *Firstchannel, *Currchannel;

void ChatInit() {
Socket_connecting = 0;
Nick_name[0];
Orignial_nick_name[0];
Nick_name[0] = 0;
Orignial_nick_name[0] = 0;
Nick_variety = 0;
szChat_channel[0] = '\0';
Input_chat_buffer[0] = '\0';
Chat_tracker_id[0];
Chat_tracker_id[0] = 0;
Getting_user_channel_info_for[0] = '\0';
Getting_user_tracker_info_for[0] = '\0';
Getting_user_channel_error = 0;
Expand Down Expand Up @@ -313,7 +324,7 @@ const char *GetChatText() {

// Send a string to be sent as chat, or scanned for messages (/msg <user>
// string)
char *SendChatString(char *line, int raw) {
char *SendChatString(const char *line, int raw) {
char szCmd[200];
char szTarget[50];
if (!Socket_connected)
Expand Down Expand Up @@ -416,7 +427,7 @@ char *GetChatUserList() {
//-1 Failed to join
// 0 joining
// 1 successfully joined
int SetNewChatChannel(char *channel) {
int SetNewChatChannel(const char *channel) {
char partstr[100];
if (!Socket_connected)
return -1;
Expand Down Expand Up @@ -492,7 +503,7 @@ const char *ChatGetString() {
return nullptr;
}

char *GetWordNum(int num, char *l_String) {
const char *GetWordNum(int num, const char *l_String) {
static char strreturn[600];
static char ptokstr[600];
char seps[10] = " \n\r\t";
Expand Down Expand Up @@ -522,7 +533,7 @@ char *GetWordNum(int num, char *l_String) {
return strreturn;
}

int AddChatUser(char *nickname) {
int AddChatUser(const char *nickname) {
Curruser = Firstuser;
while (Curruser) {
if (stricmp(nickname, Curruser->nick_name) == 0)
Expand Down Expand Up @@ -586,9 +597,9 @@ void RemoveAllChatUsers() {
Firstuser = nullptr;
}

char *ParseIRCMessage(char *Line, int iMode) {
char *ParseIRCMessage(const char *Line, int iMode) {
char szRemLine[MAXLOCALSTRING];
char *pszTempStr;
const char *pszTempStr;
char szPrefix[MAXLOCALSTRING];
char szHackPrefix[MAXLOCALSTRING];
char szTarget[MAXLOCALSTRING];
Expand Down Expand Up @@ -1014,7 +1025,7 @@ char *ParseIRCMessage(char *Line, int iMode) {
return nullptr;
}

void AddChatCommandToQueue(int command, void *data, int len) {
void AddChatCommandToQueue(int command, const void *data, int len) {
Currcommand = Firstcommand;
if (Firstcommand == nullptr) {
Firstcommand = (Chat_command *)DLLmem_malloc(sizeof(Chat_command));
Expand Down Expand Up @@ -1133,7 +1144,7 @@ void AddChannel(char *channel, uint16_t numusers, char *topic) {
Currchannel->next = nullptr;
}

char *GetTrackerIdByUser(char *nickname) {
char *GetTrackerIdByUser(const char *nickname) {
char szWhoisCmd[100];

if (nickname == (char *)-1) {
Expand Down Expand Up @@ -1161,7 +1172,7 @@ char *GetTrackerIdByUser(char *nickname) {
return nullptr;
}

char *GetChannelByUser(char *nickname) {
char *GetChannelByUser(const char *nickname) {
char szWhoisCmd[100];

if (nickname == (char *)-1) {
Expand Down
18 changes: 4 additions & 14 deletions netcon/mtclient/chat_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,12 @@ typedef struct Chat_command {
int ConnectToChatServer(const char *serveraddr, int16_t chat_port, char *nickname, char *trackerid);
void DisconnectFromChatServer();
const char *GetChatText();
char *SendChatString(char *line, int raw = 0);
char *SendChatString(const char *line, int raw = 0);
Chat_command *GetChatCommand();
char *GetChatUserList();
int SetNewChatChannel(char *channel);
int SetNewChatChannel(const char *channel);
char *GetChannelList();
char *GetTrackerIdByUser(char *nickname);
char *GetChannelByUser(char *nickname);
char *GetTrackerIdByUser(const char *nickname);
char *GetChannelByUser(const char *nickname);

const char *ChatGetString();
char *GetWordNum(int num, char *l_String);
char *ParseIRCMessage(char *Line, int iMode);
int AddChatUser(char *nickname);
int RemoveChatUser(char *nickname);
void RemoveAllChatUsers();
void AddChatCommandToQueue(int command, void *data, int len);
Chat_command *GetChatCommandFromQueue();
void FlushChatCommandQueue();
void AddChannel(char *channel, uint16_t numusers, char *topic);
void FlushChannelList();
14 changes: 7 additions & 7 deletions netcon/mtclient/mt_net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ struct vmt_descent3_struct {

extern int MT_Initialized;
// Mastertracker sockets
SOCKET TCP_game_tracker_socket;
SOCKET TCP_pilot_tracker_socket;
SOCKET TCP_chat_server_socket;
static SOCKET TCP_game_tracker_socket;
static SOCKET TCP_pilot_tracker_socket;
static SOCKET TCP_chat_server_socket;

// Mastertracker addresses (we resolve them on init, and don't want to have to do it again)
SOCKADDR_IN gtrackaddr;
SOCKADDR_IN ptrackaddr;
SOCKADDR_IN ctrackaddr;
SOCKADDR_IN sockaddr;
static SOCKADDR_IN gtrackaddr;
static SOCKADDR_IN ptrackaddr;
static SOCKADDR_IN ctrackaddr;
static SOCKADDR_IN sockaddr;

#define DLLmprintf(...) DLLDebug_ConsolePrintf(__VA_ARGS__)

Expand Down
54 changes: 35 additions & 19 deletions netcon/mtclient/mtclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,11 +452,11 @@

#include "DLLUiItems.h"

char Ourlobby[50] = "";
bool Login_aborted = false;
bool Auto_start = false;
int Bypass_chat = 0;
int ChatStarted = 0;
static char Ourlobby[50] = "";
static bool Login_aborted = false;
static bool Auto_start = false;
static int Bypass_chat = 0;
static int ChatStarted = 0;
extern int Motd_version;

d3_net_game_data_tiny DLLD3_tracker_info;
Expand All @@ -465,11 +465,27 @@ d3_net_game_data_tiny DLLD3_tracker_info;

#define MAX_GAMELIST_ITEMS 300

pxo_game_list PXOGamelist[MAX_GAMELIST_ITEMS];
int NextGameItemNo = 0;
static pxo_game_list PXOGamelist[MAX_GAMELIST_ITEMS];
static int NextGameItemNo = 0;
uint16_t DLLPXOPort = 0;

void AutoLoginAndStartGame();
static void AutoLoginAndStartGame();
static int GetGameByHandle(uint32_t handle);
static int GetPXOItemByHandle(uint32_t handle);
static int GetGameByLBNo(int selno);
static void FormatServerLine(char *fmt, int servernum, int pxonum);
static void UpdateGamelist(void *lb);
static void ResortGameList(void *lb, int type, bool invert);
static int SearchMasterTrackerGameMenu();
static void CheckPXOForAnomalies();
static void DoMTFrame();
static void DoMTGameOver();
static int JoinNewLobby(char *lobby);
static int ShowMessageOfTheDay();
static const char *SendWhisper(const char *name);
static int JoinPrivateLobby();
static int FindPilot();
static int GetPilotStats(char *pilot);

int GetGameByHandle(uint32_t handle) {
int j;
Expand Down Expand Up @@ -652,8 +668,8 @@ DLLEXPORT void DLLFUNCCALL DLLMultiCall(int eventnum);
DLLEXPORT void DLLFUNCCALL DLLMultiClose();
}

bool All_ok = true;
bool MT_Sock_inited = false;
static bool All_ok = true;
static bool MT_Sock_inited = false;

// Initializes the game function pointers
void DLLFUNCCALL DLLMultiInit(int *api_func) {
Expand Down Expand Up @@ -1645,16 +1661,16 @@ int MainMultiplayerMenu() {
#define SORT_PLAYERS 34
#define SORT_PING 35

int sort_type;
static int sort_type;

bool invert_sort_gamename = true;
bool invert_sort_gametype = true;
bool invert_sort_mission = true;
bool invert_sort_levels = true;
bool invert_sort_players = true;
bool invert_sort_ping = true;
static bool invert_sort_gamename = true;
static bool invert_sort_gametype = true;
static bool invert_sort_mission = true;
static bool invert_sort_levels = true;
static bool invert_sort_players = true;
static bool invert_sort_ping = true;

int net_game_compare(const void *arg1, const void *arg2) {
static int net_game_compare(const void *arg1, const void *arg2) {

network_game *net1 = (network_game *)arg1;
network_game *net2 = (network_game *)arg2;
Expand Down Expand Up @@ -2486,7 +2502,7 @@ int JoinNewLobby(char *lobby) {
DLLRemoveUITextItem(cancel_off_text);
}

char *SendWhisper(char *name) {
const char *SendWhisper(const char *name) {

int exit_menu = 0;
char *p;
Expand Down
14 changes: 4 additions & 10 deletions netcon/mtclient/mtclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@
#define MAX_SCRIPT_LEN 40
#define MAX_FORMAT_STRING 300

extern uint16_t DLLPXOPort;

typedef struct s_pxo_game_list {
/*
char name[MAX_GAME_NAME_LEN];
Expand All @@ -129,17 +131,9 @@ typedef struct s_pxo_game_list {

int LoginMasterTracker();
int MainMultiplayerMenu();
int SearchMasterTrackerGameMenu();
int StartMultiplayerGameMenu();
void MultiplayerOptionsMenu();
void DoMTFrame();
void DoMTGameOver();
int MTVersionCheck();
int JoinNewLobby(char *lobby);
char *SendWhisper(char *name);
int JoinPrivateLobby();
int FindPilot();
int GetPilotStats(char *pilot);
void AutoLoginAndJoinGame();
int ShowMessageOfTheDay();
#endif

#endif
32 changes: 15 additions & 17 deletions netcon/mtclient/mtgametrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@

// extern float DLLtimer_GetTime(void);
typedef float (*timer_GetTime_fp)();

extern timer_GetTime_fp DLLtimer_GetTime;

typedef void (*HandleGamePacket_fp)(uint8_t *data, int len, network_address *from);
Expand All @@ -146,33 +145,32 @@ extern nw_DoReceiveCallbacks_fp DLLnw_DoReceiveCallbacks;
#endif

typedef void (*Debug_ConsolePrintf_fp)(int n, const char *format, ...);

extern Debug_ConsolePrintf_fp DLLDebug_ConsolePrintf;

// Variables

game_list GameBuffer[MAX_GAME_BUFFERS];
int GameType; // d3 or fs
static game_list GameBuffer[MAX_GAME_BUFFERS];
static int GameType; // d3 or fs

float LastTrackerUpdate;
float LastSentToTracker;
static float LastTrackerUpdate;
static float LastSentToTracker;

float LastGameOverPacket;
float FirstGameOverPacket;
static float LastGameOverPacket;
static float FirstGameOverPacket;

int SendingGameOver;
static int SendingGameOver;

uint32_t TrackerAckdUs;
uint32_t TrackerGameIsRunning;
static uint32_t TrackerAckdUs;
static uint32_t TrackerGameIsRunning;

game_packet_header TrackerGameData;
game_packet_header GameListReq;
game_packet_header TrackAckPacket;
game_packet_header GameOverPacket;
static game_packet_header TrackerGameData;
static game_packet_header GameListReq;
static game_packet_header TrackAckPacket;
static game_packet_header GameOverPacket;

game_packet_header inpacket;
static game_packet_header inpacket;

d3_net_game_data_tiny *D3TrackerGameData;
static d3_net_game_data_tiny *D3TrackerGameData;

extern int DLLnw_ListenPort;
extern uint16_t DLLPXOPort;
Expand Down
Loading

0 comments on commit 414d521

Please sign in to comment.