Merge pull request #569 from ccfly42/online-directip-netcon

Add Descent3 Online netcon
This commit is contained in:
Azamat H. Hackimov 2024-09-15 23:07:38 +03:00 committed by GitHub
commit 9ac702dcda
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 3724 additions and 2 deletions

View File

@ -320,7 +320,7 @@ target_link_libraries(Descent3 PRIVATE
${PLATFORM_LIBS})
target_include_directories(Descent3 PRIVATE ${PROJECT_BINARY_DIR}/lib)
target_link_options(Descent3 PRIVATE $<$<PLATFORM_ID:Windows>:/DEBUG:FULL>)
add_dependencies(Descent3 get_git_hash Direct_TCP_IP_Hog HogFull NetgamesDir Parallax_Online_Hog)
add_dependencies(Descent3 get_git_hash Direct_TCP_IP_Hog Descent3_Online_TCP_IP_Hog HogFull NetgamesDir Parallax_Online_Hog)
install(TARGETS Descent3 RUNTIME BUNDLE DESTINATION .)
if(MSVC)
install(FILES $<TARGET_PDB_FILE:Descent3> DESTINATION ${CMAKE_INSTALL_BINDIR})

View File

@ -4,3 +4,4 @@ include_directories("includes")
add_subdirectory(inetfile)
add_subdirectory(lanclient)
add_subdirectory(mtclient)
add_subdirectory(descent3onlineclient)

View File

@ -0,0 +1,38 @@
set(HEADERS
chat_api.h
odtclient.h
odtstrings.h
dip_gametrack.h
)
set(CPPS
chat_api.cpp
odtclient.cpp
dip_gametrack.cpp
)
add_library(Descent3_Online_TCP_IP MODULE ${HEADERS} ${CPPS})
set_target_properties(Descent3_Online_TCP_IP PROPERTIES PREFIX "")
set_target_properties(Descent3_Online_TCP_IP PROPERTIES CXX_VISIBILITY_PRESET "hidden")
set_target_properties(Descent3_Online_TCP_IP PROPERTIES OUTPUT_NAME "Descent3 Online")
target_link_libraries(Descent3_Online_TCP_IP PRIVATE
ddio
inetfile
misc
ui
$<$<PLATFORM_ID:Windows>:ws2_32>
)
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set_target_properties(Descent3_Online_TCP_IP PROPERTIES SUFFIX ".dylib")
endif()
add_custom_target(Descent3_Online_TCP_IP_Hog
COMMAND $<TARGET_FILE:HogMaker>
"$<TARGET_FILE_DIR:Descent3>/online/Descent3 Online.d3c"
"${CMAKE_SOURCE_DIR}/netcon/descent3onlineclient/d3online.d3c.txt"
"${CMAKE_SOURCE_DIR}/scripts/data/fullhog/"
"$<TARGET_FILE_DIR:Descent3_Online_TCP_IP>"
DEPENDS Descent3_Online_TCP_IP HogMaker
COMMENT "Generate 'Descent3 Online.d3c'"
)
install(FILES "$<TARGET_FILE_DIR:Descent3>/online/Descent3 Online.d3c" DESTINATION ${CMAKE_INSTALL_DATADIR}/online)

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,73 @@
/*
* Descent 3
* Copyright (C) 2024 Descent Developers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <cstdint>
// Commands
#define CC_USER_JOINING 1 // A user had joined this channel (add him/her from the user listbox if any)
#define CC_USER_LEAVING 2 // A user has left the channel (remove him/her from the user listbox if any)
#define CC_DISCONNECTED 3 // We have been disconnected from the server (close the chat screen down)
#define CC_KICKED 4 // We were kicked out of the channel! (close the chat screen down?)
#define CC_NICKCHANGED 5 // Informing that your nickname has changed (data = "oldnick newnick")
#define CC_YOURCHANNEL 6 // data = name of the channel you are in. Only generated when you are joining #autoselect
#define MAXLOCALSTRING 600
#define MSG_REMOTE 0
#define MSG_LOCAL 1
typedef struct Chat_user {
char nick_name[33];
Chat_user *next;
} Chat_user;
typedef struct Chat_channel {
char channel_name[33];
uint16_t users;
char topic[100];
Chat_channel *next;
} Chat_channel;
typedef struct Chat_command {
int16_t command;
char data[100];
Chat_command *next;
} Chat_command;
// Prototypes
int ConnectToChatServer(const char *serveraddr, int16_t chat_port, char *nickname, char *trackerid);
void DisconnectFromChatServer();
const char *GetChatText();
const char *SendChatString(const char *line, int raw = 0);
Chat_command *GetChatCommand();
char *GetChatUserList();
int SetNewChatChannel(const char *channel);
char *GetChannelList();
char *GetTrackerIdByUser(const char *nickname);
char *GetChannelByUser(const char *nickname);
const char *ChatGetString();
const char *GetWordNum(int num, const char *l_String);
char *ParseIRCMessage(char *Line, int iMode);
int AddChatUser(const char *nickname);
int RemoveChatUser(char *nickname);
void RemoveAllChatUsers();
void AddChatCommandToQueue(int command, const void *data, int len);
Chat_command *GetChatCommandFromQueue();
void FlushChatCommandQueue();
void AddChannel(char *channel, uint16_t numusers, char *topic);
void FlushChannelList();

View File

@ -0,0 +1,7 @@
d3online.str
Descent3 Online.so
Descent3 Online.dll
Descent3 Online.dylib
d3online_main.ogf
d3online_game.ogf

View File

@ -0,0 +1,164 @@
/*
* Descent 3
* Copyright (C) 2024 Descent Developers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef WIN32
#include <windows.h>
#endif
#include <filesystem>
#include <string>
#include <sstream>
#include <thread>
#include "dip_gametrack.h"
#include "inetgetfile.h"
#if (defined(LOGGER) && (!defined(RELEASE)))
#define DLLmprintf(...) DLLDebug_ConsolePrintf(__VA_ARGS__)
#else
#define DLLmprintf(...)
#endif
#define DLLddio_MakePath(...) DLLddio_MakePath(__VA_ARGS__)
typedef void (*Debug_ConsolePrintf_fp)(int n, const char *format, ...);
extern Debug_ConsolePrintf_fp DLLDebug_ConsolePrintf;
typedef void (*ddio_MakePath_fp)(char *newPath, const char *absolutePathHeader, const char *subDir, ...);
extern ddio_MakePath_fp DLLddio_MakePath;
char tempTrackerFilename[500];
std::queue<apiServerEntry> directIpHostList;
std::queue<apiServerEntry> GetDIpGameList() {
std::queue<apiServerEntry> out;
while (!directIpHostList.empty()) {
apiServerEntry entry = directIpHostList.front();
out.push(entry);
directIpHostList.pop();
}
return out;
}
void AddApiHostToDirectIpList(const std::string &str) {
char ipbuf[16];
uint16_t iport = 2092;
const char *address = str.c_str();
const char *hostport = strchr(address, ':');
if (hostport) {
iport = atoi(hostport + 1);
size_t count = hostport - address;
if (count > 15)
return;
strncpy(ipbuf, address, count);
ipbuf[count] = '\0';
} else {
strncpy(ipbuf, address, 15);
ipbuf[15] = '\0';
}
uint32_t iaddr = inet_addr(ipbuf);
if (iaddr != INADDR_NONE) {
apiServerEntry entry = {iaddr, htons(iport)};
directIpHostList.push(entry);
}
}
void DecodeApiAnswer(const std::string &data) {
while (!directIpHostList.empty())
directIpHostList.pop();
std::stringstream ss(data);
while (!ss.eof()) {
std::string s1;
getline(ss, s1, '\n');
AddApiHostToDirectIpList(s1);
}
}
void FetchApi() {
DLLmprintf(0, "fetch api.\n");
InetGetFile *getfile;
getfile = new InetGetFile(TSETSEFLYAPIURL, tempTrackerFilename);
bool failed = false;
while (true) {
if (getfile->IsFileReceived()) {
DLLmprintf(0, "got api gameserver list.\n");
break;
} else if (getfile->IsFileError()) {
failed = true;
DLLmprintf(0, "api download failed.\n");
break;
}
}
delete getfile;
if (failed)
return;
std::string filecontents;
FILE *fp = fopen(tempTrackerFilename, "rb");
if (!fp)
return;
fseek(fp, 0, SEEK_END);
long lengthhack = ftell(fp);
filecontents.resize(lengthhack);
fseek(fp, 0, SEEK_SET);
if (fread((void *)filecontents.data(), 1, lengthhack, fp) != lengthhack) {
fclose(fp);
return;
}
fclose(fp);
DecodeApiAnswer(filecontents);
return;
}
std::thread trackthread;
void RequestDIPGameList() {
std::error_code ec;
std::filesystem::path tempPath = std::filesystem::temp_directory_path(ec);
if (ec) {
DLLmprintf(0, "Could not find temporary directory: \"%s\"", ec.message().c_str());
return;
}
DLLddio_MakePath(tempTrackerFilename, tempPath.u8string().c_str(), "Descent3", "cache", "odt.tmp", NULL);
if (trackthread.joinable())
trackthread.join();
trackthread = std::thread(FetchApi);
trackthread.detach();
}
void RequestDIPShutdown() {
if (trackthread.joinable())
trackthread.join();
}

View File

@ -0,0 +1,30 @@
/*
* Descent 3
* Copyright (C) 2024 Descent Developers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <queue>
#define TSETSEFLYAPIURL "http://api.tsetsefly.de/?format=linebyline&template=simpleServerList&get=gameServerList&filter=gameName[d3];network[directip];&request=hp"
struct apiServerEntry {
uint32_t ipv4adr;
uint16_t port;
};
void RequestDIPGameList();
void RequestDIPShutdown();
std::queue<apiServerEntry> GetDIpGameList();

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,59 @@
/*
* Descent 3
* Copyright (C) 2024 Descent Developers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _ODTCLIENT_HEADER
#define _ODTCLIENT_HEADER
#include "ui.h"
// Chat
#define CHATTRACKERNAME "irc.Descentforum.net"
#define CHATPORT 6667
#define BYPASSCHATDBKEY "BypassChatOTCP"
#define TRACKER_MENU_W 256
#define TRACKER_MENU_H 256
#define TRACKER_MENU_X (320 - (TRACKER_MENU_W / 2))
#define TRACKER_MENU_Y (240 - (TRACKER_MENU_H / 2))
#define MAXTEXTITEMS 100
#define MAXNEWWINDOWS 5
#define MAXNEWGAMEWINDOWS 5
#define MAXUIBUTTONS 20
#define MAXUITEXTS 20
#define MAXEDITS 20
#define MAXLISTS 20
#include "con_dll.h"
typedef struct s_server_game_list {
bool used;
uint32_t handle;
void *ti;
int lb_no;
} server_game_list;
int MainMultiplayerMenu();
int SearchMasterTrackerGameMenu();
int StartMultiplayerGameMenu();
int JoinNewLobby(const char *lobby);
const char *SendWhisper(const char *name);
int JoinPrivateLobby();
int FindPilot();
#endif

View File

@ -0,0 +1,96 @@
/*
* Descent 3
* Copyright (C) 2024 Descent Developers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _ODTSTRINGS_HEADER
#define _ODTSTRINGS_HEADER
#define TXT(d) GetString(d)
#define TXT_ODT_HELP1 TXT(0)
#define TXT_ODT_HELP2 TXT(1)
#define TXT_ODT_RETURNMAIN TXT(2)
#define TXT_ODT_GAMELISTHDR TXT(3)
#define TXT_ODT_BLANK TXT(4)
#define TXT_ODT_EXIT TXT(5)
#define TXT_ODT_JOINSEL TXT(6)
#define TXT_ODT_STARTNEW TXT(7)
#define TXT_ODT_SRCHADDR TXT(8) // bug, needed
#define TXT_ODT_SCANLOCAL TXT(9) // bug, needed
#define TXT_ODT_GAMENAME TXT(10)
#define TXT_ODT_MSNNAME TXT(11)
#define TXT_ODT_SCRIPTNAME TXT(12)
#define TXT_ODT_STARTGAME TXT(13)
#define TXT_ODT_MPLYROPTIONS TXT(14)
#define TXT_ODT_PREVMENU TXT(15)
#define TXT_ODT_TIMELIMIT TXT(16)
#define TXT_ODT_KILLGOAL TXT(17)
#define TXT_ODT_PPS TXT(18)
#define TXT_ODT_CFGALLOWEDSHIP TXT(19)
#define TXT_ODT_SERVERMODE TXT(20)
#define TXT_ODT_CLIENTSERVER TXT(21)
#define TXT_ODT_PEERPEER TXT(22)
#define TXT_ODT_SHIPSALLOWED TXT(23)
#define TXT_ODT_RESPAWNRATE TXT(24)
#define TXT_ODT_HELP3 TXT(25)
#define TXT_ODT_CONNECTING TXT(26)
#define TXT_ODT_CANTCONNECT TXT(27)
#define TXT_ODT_MASTERTRACKER TXT(28)
#define TXT_ODT_CANCEL TXT(29)
#define TXT_ODT_SENDPRIV TXT(30)
#define TXT_ODT_JOINPRIV TXT(31)
#define TXT_ODT_JOINCHAN TXT(32)
#define TXT_ODT_FINDPILOT TXT(33)
#define TXT_ODT_JOINSTARTGAME TXT(34)
#define TXT_ODT_INNEWLOBBY TXT(35)
#define TXT_ODT_ENTERINGLOBBY TXT(36)
#define TXT_ODT_CANTJOINLOBBY TXT(37)
#define TXT_ODT_PRIVATEMESSAGE TXT(38)
#define TXT_ODT_SEND TXT(39)
#define TXT_ODT_PILOTNAME TXT(40)
#define TXT_ODT_MESSAGE TXT(41)
#define TXT_ODT_JOIN TXT(42)
#define TXT_ODT_CHANNELNAME TXT(43)
#define TXT_ODT_SEARCH TXT(44)
#define TXT_ODT_SEARCHINGPILOT TXT(45)
#define TXT_ODT_CANBEFOUNDIN TXT(46)
#define TXT_ODT_ERRORNOTONLINE TXT(47)
#define TXT_ODT_BADNICK TXT(48)
#define TXT_ODT_PRIVMSGTO TXT(49)
#define TXT_ODT_PRIVMSGFROM TXT(50)
#define TXT_ODT_CHATDISCONNECTED TXT(51)
#define TXT_ODT_YOUAREINLOBBY TXT(52)
#define TXT_ODT_MAKEGAMEDEFAULT TXT(53)
#define TXT_ODT_RETURNTOCHAT TXT(54)
#define TXT_ODT_NO_TCPIP TXT(55)
#define TXT_ODT_ERROR TXT(56)
#define TXT_ODT_SAVESETTINGS TXT(57)
#define TXT_ODT_LOADSETTINGS TXT(58)
#define TXT_ODT_USEROTVEL TXT(59)
#define TXT_ODT_USESMOOTHING TXT(60)
#define TXT_ODT_GAME_HDR TXT(61)
#define TXT_ODT_NO_GAMES TXT(62)
#define TXT_ODT_MAXPLAYERS TXT(63)
#define TXT_ODT_ACC_WEAP_COLL TXT(64)
#define TXT_ODT_BRIGHT_PLAYERS TXT(65)
#define TXT_ODT_GAMENAME2 TXT(66)
#define TXT_ODT_GAMETYPE TXT(67)
#define TXT_ODT_MISSION TXT(68)
#define TXT_ODT_LEVEL TXT(69)
#define TXT_ODT_PLAYERS TXT(70)
#define TXT_ODT_PING TXT(71)
#endif

View File

@ -66,6 +66,7 @@
#include <cstdint>
#include "networking.h"
#include "crossplat.h"
#define HTTP_STATE_INTERNAL_ERROR 0
#define HTTP_STATE_SOCKET_ERROR 1
@ -114,7 +115,7 @@ protected:
char m_szPassword[100];
char m_szHost[200];
char m_szDir[200];
char m_szFilename[100];
char m_szFilename[_MAX_PATH];
bool m_Aborting;

View File

@ -0,0 +1,241 @@
!/!Current Restrictions:
!/!Maximum Line Length: 1024 characters
!/!Maximum Number of Lines Per String: 8 Lines
!/! Lines that begin with:
!/! !/! == comments (optional)
!/! !=! == English version of string
!/! !G! == German version of string
!/! !S! == Spanish version of string
!/! !I! == Italian version of string
!/! !F! == French version of string
!/!
!/! THERE MUST BE ENGLISH VERSIONS OF EACH STRING
!/!
!/! Note to localizers: All text when translated should stay very near the length of the
!/! English version, unless otherwise noted.
!/!
!/! Note to localizers: All %s,%d,%f and similar tokens MUST stay in the string, they will get replaced by:
!/! %s = another string
!/! %d = an integer value
!/! %f = a floating point number (a number with a decimal point)
!/! They may be moved around the string, but MUST stay in the same order (i.e. "%s got %d points" the %s must always come before %d)
!/!
!/! \t = insert a tab
!/! \n = force a newline
!/! \0-\255 = insert the number directly into byte
!/!0:Descent3 Online is a Free Service where you
!=!Descent3 Online is a Free Service where you
!/!1:can find people to play Descent 3 against.
!=!can find people to play Descent 3 against.
!/!2:Return to main menu
!=!Return to main menu
!/!3:Game Name\002\43Game Type\02\69Mission\02\96Level\02\109Players\02\126Ping
!=!Game Name\002\43Game Type\02\69Mission\02\96Level\02\109Players\02\126Ping
!/!4:
!=!
!/!5:Exit
!=!Exit
!/!6:Join Selected
!=!Join Selected
!/!7:Start a New Game
!=!Start a New Game
!/!8:Search for Games at Address:
!=!Search for Games at Address:
!/!9:Scan for Local Games
!=!Scan for Local Games
!/!10:Game Name:
!=!Game Name:
!/!11:Mission Name:
!=!Mission Name:
!/!12:Game Type:
!=!Game Type:
!/!13:Start game
!=!Start game
!/!14:Multiplayer Options
!=!Multiplayer Options
!/!15:Done
!=!Done
!/!16:Time Limit
!=!Time Limit
!/!17:Goal Limit
!=!Goal Limit
!/!18:Packets per second
!=!Packets per second
!/!19:Configure Allowed Ships/Items
!=!Configure Allowed Ships/Items
!/!20:Server mode
!=!Server mode
!/!21:Client/Server
!=!Client/Server
!/!22:Peer-Peer
!=!Peer-Peer
!/!23:Ships Allowed:
!=!Ships Allowed:
!/!24:Respawn Rate:
!=!Respawn Rate:
!/!25:You can also chat with them.
!=!You can also chat with them.
!/!26:Connecting...
!=!Connecting...
!/!27:Unable to connect.
!=!Unable to connect.
!/!28:Descent3 Online
!=!Descent3 Online
!/!29:Cancel
!=!Cancel
!/!30:Send Private Message
!=!Send Private Message
!/!31:Join Private Lobby
!=!Join Private Lobby
!/!32:Join Lobby
!=!Join Lobby
!/!33:Find Pilot
!=!Find Pilot
!/!34:Go to Games
!=!Go to Games
!/!35:Entered lobby %s!
!=!Entered lobby %s!
!/!36:Entering Lobby...
!=!Entering Lobby...
!/!37:Unable to join lobby %s!
!=!Unable to join lobby %s!
!/!38:Private Message
!=!Private Message
!/!39:Send
!=!Send
!/!40:Pilot name:
!=!Pilot name:
!/!41:Message:
!=!Message:
!/!42:Join
!=!Join
!/!43:Lobby name:
!=!Lobby name:
!/!44:Search
!=!Search
!/!45:Searching for pilot...
!=!Searching for pilot...
!/!46:\1\255\1\1**%s can be found in %s
!=!**%s can be found in %s
!/!47:\1\255\1\1**Error: %s is not on chat.
!=!\1\255\1\1**Error: %s is not on chat.
!/!48:\1\255\0\0Your nickname contains invalid characters
!=!\1\255\0\0Your nickname contains invalid characters
!/!49:\1\255\255\1Private Message to <%s>: %s
!=!\1\255\255\1Private Message to <%s>: %s
!/!50:\1\255\255\1Private Message from <%s>: %s
!=!\1\255\255\1Private Message from <%s>: %s
!/!51:Connection to the chat server has been lost!
!=!Connection to the chat server has been lost!
!/!52:You are in lobby %s.
!=!You are in lobby %s.
!/!53:%c Make this screen the default
!=!%c Make this screen the default
!/!54:Return to the chat screen
!=!Return to the chat screen
!/!55:TCP/IP is not active on your system!
!=!TCP/IP is not active on your system!
!/!56:Error
!=!Error
!/!57:Save Settings
!=!Save Settings
!/!58:Load Settings
!=!Load Settings
!/!59:Use rotational velocity
!=!Use rotational velocity
!/!60:Movement averaging
!=!Movement averaging
!/!61:Online Games
!=!Online Games
!/!62:No game was selected to join!
!=!No game was selected to join!
!/!63:Max. Players
!=!Max. Players
!/!64:%c Use Accurate weapon collisions
!=!%c Use Accurate weapon collisions
!/!65:Bright player ships
!=!Bright player ships
!/!66:Game Name
!=!Game Name
!/!67:Game Type
!=!Game Type
!/!68:Mission
!=!Mission
!/!69:Level
!=!Level
!/!70:Players
!=!Players
!/!71:Ping
!=!Ping

Binary file not shown.

Binary file not shown.