Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Feature/newprotocol #51

Open
wants to merge 29 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3a96274
New protocol stuff
xx-shitai-xx Aug 30, 2022
6dff491
New protocol stuff
xx-shitai-xx Oct 11, 2022
39de373
Remove unnecessary include
xx-shitai-xx Nov 12, 2022
e994756
Merge remote-tracking branch 'origin/master' into feature/newprotocol
xx-shitai-xx Nov 15, 2022
15a4709
Fix build error
xx-shitai-xx Nov 16, 2022
e8f6d61
Fix build error
xx-shitai-xx Nov 16, 2022
727db7a
Some changes to how packets are handled
xx-shitai-xx Nov 19, 2022
0361505
Merge remote-tracking branch 'origin/master' into feature/newprotocol
xx-shitai-xx Feb 17, 2023
e09caf0
Fix build errors
xx-shitai-xx Feb 17, 2023
c99297a
Apply suggestions from code review
xx-shitai-xx Feb 17, 2023
9ff9955
Fix build errors when building with npcserver support
xx-shitai-xx Feb 17, 2023
55fc008
Merge branch 'feature/newprotocol' of https://github.com/xtjoeytx/gse…
xx-shitai-xx Feb 17, 2023
e395516
Cleanup cmake output
xx-shitai-xx Feb 18, 2023
6d5a4bc
Make packet out handling in TLevel neater
xx-shitai-xx Feb 19, 2023
1c33290
Re-add accidental removal
xx-shitai-xx Feb 19, 2023
f78caa6
Make getting of packet for TGameAni neater
xx-shitai-xx Feb 19, 2023
2fc6e6a
Clean up some more
xx-shitai-xx Feb 19, 2023
f14e81d
Update how packets are sent to player
xx-shitai-xx Feb 19, 2023
77cfe78
Update listserver packet handling
xx-shitai-xx Feb 19, 2023
4377493
Merge remote-tracking branch 'origin/master' into feature/newprotocol
xx-shitai-xx Feb 20, 2023
52d6b7b
Minor cosmetic change
xx-shitai-xx Feb 20, 2023
0f47601
Merge remote-tracking branch 'origin/master' into feature/newprotocol
xx-shitai-xx Feb 23, 2023
d8f777f
Fix websockets for new protocol
xx-shitai-xx Feb 23, 2023
29646d4
Try to add SSL-support
xx-shitai-xx Jun 7, 2024
1edf316
Merge remote-tracking branch 'origin/master' into feature/newprotocol
xx-shitai-xx Jun 10, 2024
6836ad7
Remove junk-file
xx-shitai-xx Jun 11, 2024
5293784
Merge remote-tracking branch 'origin/dev' into feature/newprotocol
xx-shitai-xx Jun 11, 2024
d48d569
Merge remote-tracking branch 'origin/dev' into feature/newprotocol
xx-shitai-xx Jun 11, 2024
1715ec6
Reformat
xx-shitai-xx Jun 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
dependencies/v8
.git
build
cmake-build-debug/
cmake-build-release/
dependencies/depot_tools
build*
cmake-*
22 changes: 11 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ STRING(REGEX REPLACE "(-[0-9]+:[0-9]+)" "" VER_CPACK ${VER_CPACK})

# Generate version header from the above
configure_file(
${PROJECT_SOURCE_DIR}/server/include/IConfig.h.in
${PROJECT_BINARY_DIR}/server/include/IConfig.h
${PROJECT_SOURCE_DIR}/server/include/IConfig.h.in
${PROJECT_BINARY_DIR}/server/include/IConfig.h
)

option(STATIC "Compile as a static runtime." ON)
Expand Down Expand Up @@ -127,12 +127,12 @@ if(APPLE)
set(CPACK_GENERATOR DragNDrop)
set(CPACK_DMG_VOLUME_NAME "${PROJECT_NAME} ${VER_FULL}")
set(
CPACK_DMG_DS_STORE_SETUP_SCRIPT
${PROJECT_SOURCE_DIR}/resources/packaging/osx/DMGSetup.scpt
CPACK_DMG_DS_STORE_SETUP_SCRIPT
${PROJECT_SOURCE_DIR}/resources/packaging/osx/DMGSetup.scpt
)
set(
CPACK_DMG_BACKGROUND_IMAGE
${PROJECT_SOURCE_DIR}/resources/packaging/osx/DMGBackground.tif
CPACK_DMG_BACKGROUND_IMAGE
${PROJECT_SOURCE_DIR}/resources/packaging/osx/DMGBackground.tif
)
elseif(WIN32)
set(CPACK_GENERATOR "ZIP")
Expand Down Expand Up @@ -160,8 +160,8 @@ include(CPack)

# Generate version header from the above
configure_file(
${PROJECT_SOURCE_DIR}/server/include/IConfig.h.in
${PROJECT_BINARY_DIR}/server/include/IConfig.h
${PROJECT_SOURCE_DIR}/server/include/IConfig.h.in
${PROJECT_BINARY_DIR}/server/include/IConfig.h
)

if(APPLE)
Expand Down Expand Up @@ -200,8 +200,8 @@ elseif(WIN32)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
set(
CMAKE_CXX_FLAGS_RELWITHDEBINFO
"${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /MTd"
CMAKE_CXX_FLAGS_RELWITHDEBINFO
"${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /MTd"
)
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /MT")
cmake_policy(SET CMP0043 NEW)
Expand Down Expand Up @@ -234,7 +234,7 @@ elseif(WIN32)
else()
set(MAKE_TESTS ON)
if(STATIC)
# SET(CMAKE_EXE_LINKER_FLAGS "-static")
#SET(CMAKE_EXE_LINKER_FLAGS "-static")
endif()

add_definitions(-D_DEFAULT_SOURCE -D_POSIX_C_SOURCE=1 -DNDEBUG=1 -DENABLE_SCRIPTENV_DEBUG=1)
Expand Down
13 changes: 0 additions & 13 deletions bin/servers/default/weapons/weapon-gr_movement.txt

This file was deleted.

2 changes: 1 addition & 1 deletion cmake/FindMiniupnpc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ set(MINIUPNP_STATIC_LIBRARIES ${MINIUPNP_STATIC_LIBRARY})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
MiniUPnPc DEFAULT_MSG
Miniupnpc DEFAULT_MSG
MINIUPNP_INCLUDE_DIR
MINIUPNP_LIBRARY
)
Expand Down
2 changes: 1 addition & 1 deletion dependencies/gs2lib
Submodule gs2lib updated from 445cda to 7185f9
2 changes: 1 addition & 1 deletion server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
# You should have received a copy of the GNU General Public License
# along with GS2Emu. If not, see <http://www.gnu.org/licenses/>.
#

include(CheckFunctionExists)
include(CheckSymbolExists)

Expand Down Expand Up @@ -248,6 +247,7 @@ target_include_directories(${TARGET_NAME} PUBLIC ${GS2COMPILER_INCLUDE_DIRECTORY

add_dependencies(${TARGET_NAME} gs2compiler)
target_link_libraries(${TARGET_NAME} gs2compiler)

add_dependencies(${TARGET_NAME} gs2lib)
target_link_libraries(${TARGET_NAME} gs2lib)

Expand Down
3 changes: 2 additions & 1 deletion server/include/Animation/TGameAni.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <string>
#include <optional>
#include "CString.h"
#include "TPlayer.h"

class TServer;

Expand Down Expand Up @@ -72,7 +73,7 @@ class TGameAni

//! Get the bytecode packet to send to clients for the ani script
//! \return bytecode packet
CString getBytecodePacket() const;
void sendBytecodePacket(TPlayer* p) const;

//! Load a TGameAni from the filesystem
//! \param server Global server pointer so we can fetch the correct filesystem
Expand Down
134 changes: 67 additions & 67 deletions server/include/Misc/CUPNP.h
Original file line number Diff line number Diff line change
@@ -1,68 +1,68 @@
#ifdef UPNP
#ifndef CUPNP_H
#define CUPNP_H
#include <set>
#include <memory.h>
#include "CString.h"
#include "miniupnpc/miniwget.h"
#include "miniupnpc/miniupnpc.h"
#include "miniupnpc/upnpcommands.h"
class TServer;
class CUPNP
{
public:
CUPNP(TServer* server)
{
this->server = server;
}
// Allows std::thread to work.
void operator()()
{
discover();
add_port_forward(local_ip, port);
}
void initialize(const char* local_ip, const char* port)
{
this->local_ip = local_ip;
this->port = port;
}
// Finds a valid UPNP device.
void discover();
// Adds a port forward.
void add_port_forward(const CString& addr, const CString& port);
// Removes a port forward.
void remove_port_forward(const CString& port);
// Removes all the port forwards created by the add_port_forward command.
void remove_all_forwarded_ports()
{
while (!ports_forwarded.empty())
remove_port_forward(*ports_forwarded.rbegin());
ports_forwarded.clear();
}
// Returns true if the port was successfully forwarded.
bool port_was_forwarded(const CString& port)
{
return ports_forwarded.find(port) != ports_forwarded.end();
}
private:
TServer* server;
std::set<CString> ports_forwarded;
CString local_ip;
CString port;
struct UPNPUrls urls;
struct IGDdatas data;
};
#endif
#ifdef UPNP
#ifndef CUPNP_H
#define CUPNP_H

#include <set>
#include <memory.h>
#include "CString.h"
#include "miniwget.h"
#include "miniupnpc.h"
#include "upnpcommands.h"

class TServer;

class CUPNP
{
public:
CUPNP(TServer* server)
{
this->server = server;
}

// Allows std::thread to work.
void operator()()
{
discover();
add_port_forward(local_ip, port);
}

void initialize(const char* local_ip, const char* port)
{
this->local_ip = local_ip;
this->port = port;
}

// Finds a valid UPNP device.
void discover();

// Adds a port forward.
void add_port_forward(const CString& addr, const CString& port);

// Removes a port forward.
void remove_port_forward(const CString& port);

// Removes all the port forwards created by the add_port_forward command.
void remove_all_forwarded_ports()
{
while (!ports_forwarded.empty())
remove_port_forward(*ports_forwarded.rbegin());
ports_forwarded.clear();
}

// Returns true if the port was successfully forwarded.
bool port_was_forwarded(const CString& port)
{
return ports_forwarded.find(port) != ports_forwarded.end();
}

private:
TServer* server;
std::set<CString> ports_forwarded;
CString local_ip;
CString port;
struct UPNPUrls urls;
struct IGDdatas data;
};

#endif
#endif
22 changes: 12 additions & 10 deletions server/include/TLevel/TLevel.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <optional>
#include "IUtil.h"
#include "CString.h"
#include "IEnums.h"
#include "TPacket.h"
#include "TLevelBaddy.h"
#include "TLevelBoardChange.h"
#include "TLevelChest.h"
Expand Down Expand Up @@ -42,16 +44,16 @@ class TLevel
TLevel* clone();

// get crafted packets
CString getBaddyPacket(int clientVersion = CLVER_2_17);
CString getBoardPacket();
CString getLayerPacket(int i);
CString getBoardChangesPacket(time_t time);
CString getBoardChangesPacket2(time_t time);
CString getChestPacket(TPlayer *pPlayer);
CString getHorsePacket();
CString getLinksPacket();
CString getNpcsPacket(time_t time, int clientVersion = CLVER_2_17);
CString getSignsPacket(TPlayer *pPlayer);
std::vector<TPacket<PlayerOutPacket>> getBaddyPackets(int clientVersion = CLVER_2_17);
TPacket<PlayerOutPacket> getBoardPacket();
TPacket<PlayerOutPacket> getLayerPacket(int i);
void getBoardChangesPacket(TPlayer *pPlayer, time_t time);
void getBoardChangesPacket2(TPlayer *pPlayer, time_t time);
void getChestPacket(TPlayer *pPlayer);
void getHorsePacket(TPlayer *pPlayer);
void getLinksPacket(TPlayer *pPlayer);
void getNpcsPacket(TPlayer *pPlayer, time_t time, int clientVersion = CLVER_2_17);
void getSignsPacket(TPlayer *pPlayer);

//! Gets the actual level name.
//! \return The actual level name.
Expand Down
17 changes: 17 additions & 0 deletions server/include/TPacket.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

#ifndef GS2EMU_TPACKET_H
#define GS2EMU_TPACKET_H

#include <utility>

#include "IEnums.h"
#include "CString.h"


template <class T>
struct TPacket {
T Id;
CString Data;
};

#endif //GS2EMU_TPACKET_H
13 changes: 10 additions & 3 deletions server/include/TPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
#include "TAccount.h"
#include "CEncryption.h"
#include "CSocket.h"
#include "TPacket.h"

#ifdef V8NPCSERVER
#include "ScriptBindings.h"
#include "TPacket.h"

#endif

class TLevel;
Expand Down Expand Up @@ -103,7 +106,10 @@ class TPlayer : public TAccount, public CSocketStub

// Socket-Functions
bool doMain();
void sendPacket(CString pPacket, bool appendNL = true);
template <class T>
void sendPacket(const TPacket<T>& packet, bool sendNow = false, bool appendNL = true) { sendPacket((unsigned char)packet.Id, packet.Data, sendNow, appendNL); };
void sendPacket(unsigned char packetId, const CString& pPacket, bool sendNow = false, bool appendNL = true);
void sendPacketOld(CString pPacket, bool appendNL = true);
bool sendFile(const CString& pFile);
bool sendFile(const CString& pPath, const CString& pFile);

Expand Down Expand Up @@ -301,7 +307,8 @@ class TPlayer : public TAccount, public CSocketStub
bool msgPLI_UPDATEPACKAGEREQUESTFILE(CString& pPacket);
bool msgPLI_RC_UNKNOWN162(CString& pPacket);

private:
bool newProtocol;
xx-shitai-xx marked this conversation as resolved.
Show resolved Hide resolved
private:
// Login functions.
bool sendLoginClient();
bool sendLoginNC();
Expand Down Expand Up @@ -333,7 +340,7 @@ class TPlayer : public TAccount, public CSocketStub
int codepage;
TLevel *level;
int id, type, versionID;
time_t lastData, lastMovement, lastChat, lastNick, lastMessage, lastSave, last1m;
time_t lastData, lastMovement, lastChat, lastNick, lastMessage, lastSave, last1m;
xx-shitai-xx marked this conversation as resolved.
Show resolved Hide resolved
std::vector<SCachedLevel*> cachedLevels;
std::map<CString, CString> rcLargeFiles;
std::map<CString, TLevel*> spLevels;
Expand Down
5 changes: 3 additions & 2 deletions server/include/TScriptClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <string>
#include "CString.h"
#include "SourceCode.h"
#include "TPlayer.h"

class TServer;
class TScriptClass
Expand All @@ -15,8 +16,8 @@ class TScriptClass
~TScriptClass();

// Functions -> Inline Get-Functions
CString getClassPacket() const;
void sendClassPacket(TPlayer *p) const;

const std::string& getName() const {
return _className;
}
Expand Down
Loading