diff --git a/.gitignore b/.gitignore index 90e29340..3e92a0bc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,14 @@ +# Finder files (macOS) .DS_Store -*.o + +# Build products newserv + +# CMake files +CMakeCache.txt +CMakeFiles +Makefile +CTestTestFile.cmake +Testing +cmake_install.cmake +install_manifest.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..3daa119f --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,72 @@ +cmake_minimum_required(VERSION 3.10) + + + +# Project setup + +project(newserv) + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED True) +if (MSVC) + add_compile_options(/W4 /WX) +else() + add_compile_options(-Wall -Wextra -Werror) +endif() + +include_directories("/usr/local/include") +link_directories("/usr/local/lib") + + + +# Executable definitions + +find_path (LIBEVENT_INCLUDE_DIR NAMES event.h) +find_library (LIBEVENT_LIBRARY NAMES event) +find_library (LIBEVENT_CORE NAMES event_core) +find_library (LIBEVENT_THREAD NAMES event_pthreads) +set (LIBEVENT_INCLUDE_DIRS ${LIBEVENT_INCLUDE_DIR}) +set (LIBEVENT_LIBRARIES + ${LIBEVENT_LIBRARY} + ${LIBEVENT_CORE} + ${LIBEVENT_THREAD}) + +add_executable(newserv + src/FileContentsCache.cc + src/Menu.cc + src/PSOProtocol.cc + src/Client.cc + src/Lobby.cc + src/ServerState.cc + src/Server.cc + src/License.cc + src/PSOEncryption.cc + src/Player.cc + src/SendCommands.cc + src/ChatCommands.cc + src/ReceiveSubcommands.cc + src/ReceiveCommands.cc + src/Version.cc + src/Items.cc + src/LevelTable.cc + src/Compression.cc + src/Quest.cc + src/RareItemSet.cc + src/Map.cc + src/NetworkAddresses.cc + src/Text.cc + src/DNSServer.cc + src/ProxyServer.cc + src/Shell.cc + src/ServerShell.cc + src/ProxyShell.cc + src/Main.cc +) +target_include_directories(newserv PUBLIC ${LIBEVENT_INCLUDE_DIR}) +target_link_libraries(newserv phosg ${LIBEVENT_LIBRARIES}) + + + +# Installation configuration + +install(TARGETS newserv DESTINATION bin) diff --git a/Makefile b/Makefile deleted file mode 100644 index bb7b66b7..00000000 --- a/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -OBJECTS=FileContentsCache.o Menu.o PSOProtocol.o Client.o Lobby.o \ - ServerState.o Server.o License.o PSOEncryption.o Player.o SendCommands.o \ - ChatCommands.o ReceiveSubcommands.o ReceiveCommands.o Version.o Items.o \ - LevelTable.o Compression.o Quest.o RareItemSet.o Map.o NetworkAddresses.o \ - Text.o DNSServer.o ProxyServer.o Shell.o ServerShell.o ProxyShell.o Main.o -CXX=g++ -CXXFLAGS=-I/opt/homebrew/include -I/opt/local/include -I/usr/local/include -std=c++20 -g -DHAVE_INTTYPES_H -DHAVE_NETINET_IN_H -Wall -Werror -LDFLAGS=-L/opt/homebrew/lib -L/opt/local/lib -L/usr/local/lib -std=c++20 -levent -levent_pthreads -lphosg -lpthread - -all: newserv - -newserv: $(OBJECTS) - $(CXX) $(OBJECTS) $(LDFLAGS) -o newserv - -clean: - find . -name \*.o -delete - rm -rf *.dSYM newserv newserv-dns gmon.out - -.PHONY: clean test diff --git a/PSODolphinConfig.py b/PSODolphinConfig.py deleted file mode 100644 index 985fb952..00000000 --- a/PSODolphinConfig.py +++ /dev/null @@ -1,137 +0,0 @@ -#!/bin/env python3 - -import argparse -import os -import pwd -import re -import stat -import subprocess -import sys -import time - - -def change_user(username): - try: - user_info = pwd.getpwnam(username) - except KeyError: - print("user %s does not exist" % (username,)) - raise - os.setregid(user_info.pw_gid, user_info.pw_gid) - os.setreuid(user_info.pw_uid, user_info.pw_uid) - - -def main(argv): - parser = argparse.ArgumentParser(description="Runs Dolphin as a non-privileged user with access to the privileged tap0 network interface. Run this script with sudo; it will run Dolphin as the user you sudo'ed from and provide it access to the tap interface. It will also automatically configure the tap interface when Dolphin first opens it.") - parser.add_argument( - "--dolphin-path", "-d", - action="store", - dest="dolphin_path", - default="./Dolphin.app/Contents/MacOS/Dolphin", - help="Path to Dolphin executable. Defaults to Dolphin.app/Contents/MacOS/Dolphin in current directory.", - ) - parser.add_argument( - "--memwatch-path", "-m", - action="store", - dest="memwatch_path", - default="memwatch", - help="Path to memwatch executable. Defaults to memwatch (assumes it's installed somewhere on $PATH).", - ) - parser.add_argument( - "--tap-interface", "-I", - action="store", - dest="tap_interface", - default="/dev/tap0", - help="Tap interface to use. Defaults to /dev/tap0.", - ) - parser.add_argument( - "--tap-ip", "-i", - action="store", - dest="tap_ip", - default="192.168.0.5/24", - help="IP address and subnet bits to assign to tap interface. Defaults to 192.168.0.5/24. This should match the gateway and DNS server addresses configured in PSO's network settings.", - ) - args = parser.parse_args() - - try: - username = os.environ['SUDO_USER'] - except KeyError: - print('$SUDO_USER not set; use `sudo -E`') - return 1 - - tap_match = re.match(r'^/dev/tap([0-9]+)$', args.tap_interface) - if tap_match is None: - print('tap interface name must begin with /dev/tap') - return 1 - tap_interface_number = int(tap_match.group(1)) - tap_name = 'tap%d' % (tap_interface_number,) - - # 1. open tap and configure it - print("starting and configuring " + tap_name) - tap_fd = os.open(args.tap_interface, os.O_RDWR) - os.set_inheritable(tap_fd, True) - subprocess.check_call(['ifconfig', tap_name, args.tap_ip], stderr=subprocess.DEVNULL) - subprocess.check_call(['ifconfig', tap_name, 'up'], stderr=subprocess.DEVNULL) - subprocess.check_call(['ifconfig', tap_name, 'mtu', '9000'], stderr=subprocess.DEVNULL) - - # 2. fork a Dolphin process, dropping privileges first - print("starting dolphin") - dolphin_proc = subprocess.Popen([args.dolphin_path], - preexec_fn=lambda: change_user(username), pass_fds=(tap_fd,)) - time.sleep(1) - - # 3. create a temp file for dolphin to open instead of /dev/tapN - print("creating temp file") - tmpfile_fd = os.open("/tmp/dnet", os.O_CREAT | os.O_RDWR, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) - os.close(tmpfile_fd) - os.chmod("/tmp/dnet", stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) - - # 4. modify dolphin's memory to make it upen the temp file - print("redirecting /dev/tap0 for dolphin") - addresses_str = subprocess.check_output([args.memwatch_path, str(dolphin_proc.pid), 'find', '\"/dev/tap0\"'], stderr=subprocess.DEVNULL) - for line in addresses_str.splitlines(): - tokens = line.split() - if len(tokens) != 3: - continue - print("redirecting /dev/tap0 to /tmp/dnet at %s in dolphin" % (tokens[1],)) - subprocess.check_call([args.memwatch_path, str(dolphin_proc.pid), "access", tokens[1], "rwx"], stderr=subprocess.DEVNULL) - subprocess.check_call([args.memwatch_path, str(dolphin_proc.pid), "write", tokens[1], "\"/tmp/dnet\""], stderr=subprocess.DEVNULL) - subprocess.check_call([args.memwatch_path, str(dolphin_proc.pid), "access", tokens[1], "r-x"], stderr=subprocess.DEVNULL) - - # step 5: use lsof to find out when dolphin opens /tmp/dnet - print("waiting for temp file to open") - dolphin_tap0_fd = -1 - while dolphin_tap0_fd < 0: - time.sleep(1) - result = subprocess.check_output(["lsof", "-p", str(dolphin_proc.pid)], stderr=subprocess.DEVNULL) - for line in result.splitlines(): - if b'/tmp/dnet' not in line: - continue - - fd_str = line.split()[3] - dolphin_tap0_fd = int(fd_str[0:-len(fd_str.lstrip(b'0123456789'))]) - print("found open tap fd %d in dolphin" % (dolphin_tap0_fd,)) - - # step 6: use memwatch to move the tap fd into place - print("replacing temp fd %d with tap fd %d in dolphin" % (dolphin_tap0_fd, - tap_fd)) - assembly_contents = b"""start: - mov rax, 0x000000000200005A # dup2(from_fd, to_fd) - mov rdi, %d - mov rsi, %d - syscall - - # close the original fd. note that rdi is preserved during the syscall so we - # don't need to reload it - mov rax, 0x0000000002000006 # close(fd) - syscall - - ret -""" % (tap_fd, dolphin_tap0_fd) - subprocess.run([args.memwatch_path, str(dolphin_proc.pid), "--", "run", "-"], input=assembly_contents, stderr=subprocess.DEVNULL) - - # ok we're done; dolphin is running as a non-privileged user with the tap open - return 0 - - -if __name__ == '__main__': - sys.exit(main(sys.argv)) diff --git a/README.md b/README.md index f073e3eb..e7e0a7e6 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,9 @@ This project is primarily for my own nostalgia. Feel free to peruse if you'd lik Currently this code should build on macOS and Ubuntu. It might build on other Linux flavors, but don't expect it to work on Windows at all. So, you've read all of the above and you want to try it out? Here's what you do: -- Make sure you have libevent installed (use Homebrew in macOS, or install libevent-dev in Linux). +- Make sure you have CMake and libevent installed (use Homebrew in macOS, or install libevent-dev in Linux). - Build and install phosg (https://github.com/fuzziqersoftware/phosg). -- Run `make`. +- Run `cmake . && make`. - Edit system/config.json to your liking. - Run `./newserv` in the newserv directory. This will start the game server and run the interactive shell. (You can disable the interactive shell later by editing config.json.) You may need `sudo` if newserv's built-in DNS server is enabled. - Use the interactive shell to add a license. Run `help` in the shell to see how to do this. @@ -39,7 +39,7 @@ So, you've read all of the above and you want to try it out? Here's what you do: If you're running PSO on a real GameCube, you can make PSO connect to newserv by changing its default gateway and DNS server addresses to newserv's address. If you're emulating PSO GC using Dolphin on Mac OS (like I am), you can make it connect to newserv by doing this: -- Use a build of Dolphin that has tapserver support (this may mean building it from master yourself). +- Use a build of Dolphin that has tapserver support. - Install tapserver (https://github.com/fuzziqersoftware/tapserver). - In PSO, manually configure your network settings as follows: IP address = `192.168.0.200`, subnet mask = `255.255.255.0`, default gateway = `192.168.0.5`, DNS server address 1 = `192.168.0.5`. - Start Dolphin and newserv. diff --git a/ChatCommands.cc b/src/ChatCommands.cc similarity index 91% rename from ChatCommands.cc rename to src/ChatCommands.cc index a3513fbf..c36712d0 100644 --- a/ChatCommands.cc +++ b/src/ChatCommands.cc @@ -379,8 +379,8 @@ static void check_is_leader(shared_ptr l, shared_ptr c) { //////////////////////////////////////////////////////////////////////////////// // Message commands -static void command_lobby_info(shared_ptr s, shared_ptr l, - shared_ptr c, const char16_t* args) { +static void command_lobby_info(shared_ptr, shared_ptr l, + shared_ptr c, const char16_t*) { // no preconditions - everyone can use this command if (!l) { @@ -407,22 +407,21 @@ static void command_lobby_info(shared_ptr s, shared_ptr l, } } -static void command_ax(shared_ptr s, shared_ptr l, +static void command_ax(shared_ptr, shared_ptr, shared_ptr c, const char16_t* args) { check_privileges(c, Privilege::Announce); log(INFO, "[$ax from %010u] %S\n", c->license->serial_number, args); } -static void command_announce(shared_ptr s, shared_ptr l, +static void command_announce(shared_ptr s, shared_ptr, shared_ptr c, const char16_t* args) { check_privileges(c, Privilege::Announce); send_text_message(s, args); } -static void command_arrow(shared_ptr s, shared_ptr l, +static void command_arrow(shared_ptr, shared_ptr l, shared_ptr c, const char16_t* args) { // no preconditions - c->lobby_arrow_color = stoull(encode_sjis(args), NULL, 0); if (!l->is_game()) { send_arrow_update(l); @@ -432,8 +431,8 @@ static void command_arrow(shared_ptr s, shared_ptr l, //////////////////////////////////////////////////////////////////////////////// // Lobby commands -static void command_cheat(shared_ptr s, shared_ptr l, - shared_ptr c, const char16_t* args) { +static void command_cheat(shared_ptr, shared_ptr l, + shared_ptr c, const char16_t*) { check_is_game(l, true); check_is_leader(l, c); @@ -455,7 +454,7 @@ static void command_cheat(shared_ptr s, shared_ptr l, } } -static void command_lobby_event(shared_ptr s, shared_ptr l, +static void command_lobby_event(shared_ptr, shared_ptr l, shared_ptr c, const char16_t* args) { check_is_game(l, false); check_privileges(c, Privilege::ChangeEvent); @@ -470,7 +469,7 @@ static void command_lobby_event(shared_ptr s, shared_ptr l, send_change_event(l, l->event); } -static void command_lobby_event_all(shared_ptr s, shared_ptr l, +static void command_lobby_event_all(shared_ptr s, shared_ptr, shared_ptr c, const char16_t* args) { check_privileges(c, Privilege::ChangeEvent); @@ -490,7 +489,7 @@ static void command_lobby_event_all(shared_ptr s, shared_ptr } } -static void command_lobby_type(shared_ptr s, shared_ptr l, +static void command_lobby_type(shared_ptr, shared_ptr l, shared_ptr c, const char16_t* args) { check_is_game(l, false); check_privileges(c, Privilege::ChangeEvent); @@ -516,7 +515,7 @@ static void command_lobby_type(shared_ptr s, shared_ptr l, //////////////////////////////////////////////////////////////////////////////// // Game commands -static void command_password(shared_ptr s, shared_ptr l, +static void command_password(shared_ptr, shared_ptr l, shared_ptr c, const char16_t* args) { check_is_game(l, true); check_is_leader(l, c); @@ -533,7 +532,7 @@ static void command_password(shared_ptr s, shared_ptr l, } } -static void command_min_level(shared_ptr s, shared_ptr l, +static void command_min_level(shared_ptr, shared_ptr l, shared_ptr c, const char16_t* args) { check_is_game(l, true); check_is_leader(l, c); @@ -544,7 +543,7 @@ static void command_min_level(shared_ptr s, shared_ptr l, l->min_level + 1); } -static void command_max_level(shared_ptr s, shared_ptr l, +static void command_max_level(shared_ptr, shared_ptr l, shared_ptr c, const char16_t* args) { check_is_game(l, true); check_is_leader(l, c); @@ -648,16 +647,16 @@ static void command_edit(shared_ptr s, shared_ptr l, s->send_lobby_join_notifications(l, c); } -static void command_change_bank(shared_ptr s, shared_ptr l, - shared_ptr c, const char16_t* args) { +static void command_change_bank(shared_ptr, shared_ptr, + shared_ptr c, const char16_t*) { check_version(c, GameVersion::BB); // TODO: implement this // TODO: make sure the bank name is filesystem-safe } -static void command_convert_char_to_bb(shared_ptr s, shared_ptr l, - shared_ptr c, const char16_t* args) { +static void command_convert_char_to_bb(shared_ptr s, + shared_ptr l, shared_ptr c, const char16_t* args) { check_is_game(l, false); check_not_version(c, GameVersion::BB); @@ -786,7 +785,7 @@ static void command_ban(shared_ptr s, shared_ptr l, //////////////////////////////////////////////////////////////////////////////// // Cheat commands -static void command_warp(shared_ptr s, shared_ptr l, +static void command_warp(shared_ptr, shared_ptr l, shared_ptr c, const char16_t* args) { check_is_game(l, true); check_cheats_enabled(l); @@ -815,8 +814,8 @@ static void command_warp(shared_ptr s, shared_ptr l, send_warp(c, area); } -static void command_infinite_hp(shared_ptr s, shared_ptr l, - shared_ptr c, const char16_t* args) { +static void command_infinite_hp(shared_ptr, shared_ptr l, + shared_ptr c, const char16_t*) { check_is_game(l, true); check_cheats_enabled(l); @@ -824,8 +823,8 @@ static void command_infinite_hp(shared_ptr s, shared_ptr l, send_text_message_printf(c, "$C6Infinite HP %s", c->infinite_hp ? "enabled" : "disabled"); } -static void command_infinite_tp(shared_ptr s, shared_ptr l, - shared_ptr c, const char16_t* args) { +static void command_infinite_tp(shared_ptr, shared_ptr l, + shared_ptr c, const char16_t*) { check_is_game(l, true); check_cheats_enabled(l); @@ -833,7 +832,7 @@ static void command_infinite_tp(shared_ptr s, shared_ptr l, send_text_message_printf(c, "$C6Infinite TP %s", c->infinite_tp ? "enabled" : "disabled"); } -static void command_item(shared_ptr s, shared_ptr l, +static void command_item(shared_ptr, shared_ptr l, shared_ptr c, const char16_t* args) { check_is_game(l, true); check_cheats_enabled(l); diff --git a/ChatCommands.hh b/src/ChatCommands.hh similarity index 100% rename from ChatCommands.hh rename to src/ChatCommands.hh diff --git a/Client.cc b/src/Client.cc similarity index 100% rename from Client.cc rename to src/Client.cc diff --git a/Client.hh b/src/Client.hh similarity index 100% rename from Client.hh rename to src/Client.hh diff --git a/Compression.cc b/src/Compression.cc similarity index 92% rename from Compression.cc rename to src/Compression.cc index 31b593c4..7f9f8c36 100644 --- a/Compression.cc +++ b/src/Compression.cc @@ -101,23 +101,24 @@ struct prs_compress_ctx { string prs_compress(const string& data) { prs_compress_ctx pc; + ssize_t data_ssize = static_cast(data.size()); ssize_t read_offset = 0; - while (read_offset < static_cast(data.size())) { + while (read_offset < data_ssize) { // look for a chunk of data in history matching what's at the current offset ssize_t best_offset = 0; - size_t best_size = 0; + ssize_t best_size = 0; for (ssize_t this_offset = -3; - (this_offset + data.size() >= 0) && + (this_offset + data_ssize >= 0) && (this_offset > -0x1FF0) && (best_size < 255); this_offset--) { // for this offset, expand the match as much as possible - size_t this_size = 1; + ssize_t this_size = 1; while ((this_size < 0x100) && // max copy size is 255 bytes ((this_offset + this_size) < 0) && // don't copy past the read offset - (this_size <= data.size() - read_offset) && // don't copy past the end + (this_size <= data_ssize - read_offset) && // don't copy past the end !memcmp(data.data() + read_offset + this_offset, data.data() + read_offset, this_size)) { this_size++; diff --git a/Compression.hh b/src/Compression.hh similarity index 100% rename from Compression.hh rename to src/Compression.hh diff --git a/DNSServer.cc b/src/DNSServer.cc similarity index 94% rename from DNSServer.cc rename to src/DNSServer.cc index f6e2751e..fbdd0064 100644 --- a/DNSServer.cc +++ b/src/DNSServer.cc @@ -54,7 +54,7 @@ void DNSServer::dispatch_on_receive_message(evutil_socket_t fd, reinterpret_cast(ctx)->on_receive_message(fd, events); } -void DNSServer::on_receive_message(int fd, short event) { +void DNSServer::on_receive_message(int fd, short) { for (;;) { sockaddr_in remote; socklen_t remote_size = sizeof(sockaddr_in); diff --git a/DNSServer.hh b/src/DNSServer.hh similarity index 100% rename from DNSServer.hh rename to src/DNSServer.hh diff --git a/FileContentsCache.cc b/src/FileContentsCache.cc similarity index 100% rename from FileContentsCache.cc rename to src/FileContentsCache.cc diff --git a/FileContentsCache.hh b/src/FileContentsCache.hh similarity index 100% rename from FileContentsCache.hh rename to src/FileContentsCache.hh diff --git a/Items.cc b/src/Items.cc similarity index 95% rename from Items.cc rename to src/Items.cc index 07c70a2e..968738f6 100644 --- a/Items.cc +++ b/src/Items.cc @@ -141,8 +141,7 @@ using namespace std; //////////////////////////////////////////////////////////////////////////////// -void player_use_item(shared_ptr l, shared_ptr c, - size_t item_index) { +void player_use_item(shared_ptr c, size_t item_index) { ssize_t equipped_weapon = -1; // ssize_t equipped_armor = -1; @@ -282,7 +281,8 @@ int32_t CommonItemCreator::decide_item_type(bool is_box) const { } ItemData CommonItemCreator::create_drop_item(bool is_box, uint8_t episode, - uint8_t difficulty, uint8_t area, uint8_t section_id) const { + uint8_t difficulty, uint8_t area, uint8_t) const { + // TODO: use the section ID (last argument) to vary drop frequencies appropriately // change the area if it's invalid (data for the bosses are actually in other areas) if (area > 10) { if (episode == 1) { diff --git a/Items.hh b/src/Items.hh similarity index 85% rename from Items.hh rename to src/Items.hh index 356cdc64..a1c005fd 100644 --- a/Items.hh +++ b/src/Items.hh @@ -7,8 +7,7 @@ #include "Lobby.hh" #include "Client.hh" -void player_use_item(std::shared_ptr l, std::shared_ptr c, - size_t item_index); +void player_use_item(std::shared_ptr c, size_t item_index); struct CommonItemCreator { std::vector enemy_item_categories; diff --git a/LevelTable.cc b/src/LevelTable.cc similarity index 100% rename from LevelTable.cc rename to src/LevelTable.cc diff --git a/LevelTable.hh b/src/LevelTable.hh similarity index 100% rename from LevelTable.hh rename to src/LevelTable.hh diff --git a/License.cc b/src/License.cc similarity index 100% rename from License.cc rename to src/License.cc diff --git a/License.hh b/src/License.hh similarity index 100% rename from License.hh rename to src/License.hh diff --git a/Lobby.cc b/src/Lobby.cc similarity index 100% rename from Lobby.cc rename to src/Lobby.cc diff --git a/Lobby.hh b/src/Lobby.hh similarity index 100% rename from Lobby.hh rename to src/Lobby.hh diff --git a/Main.cc b/src/Main.cc similarity index 100% rename from Main.cc rename to src/Main.cc diff --git a/Map.cc b/src/Map.cc similarity index 100% rename from Map.cc rename to src/Map.cc diff --git a/Map.hh b/src/Map.hh similarity index 100% rename from Map.hh rename to src/Map.hh diff --git a/Menu.cc b/src/Menu.cc similarity index 100% rename from Menu.cc rename to src/Menu.cc diff --git a/Menu.hh b/src/Menu.hh similarity index 100% rename from Menu.hh rename to src/Menu.hh diff --git a/NetworkAddresses.cc b/src/NetworkAddresses.cc similarity index 100% rename from NetworkAddresses.cc rename to src/NetworkAddresses.cc diff --git a/NetworkAddresses.hh b/src/NetworkAddresses.hh similarity index 100% rename from NetworkAddresses.hh rename to src/NetworkAddresses.hh diff --git a/PSOEncryption.cc b/src/PSOEncryption.cc similarity index 100% rename from PSOEncryption.cc rename to src/PSOEncryption.cc diff --git a/PSOEncryption.hh b/src/PSOEncryption.hh similarity index 100% rename from PSOEncryption.hh rename to src/PSOEncryption.hh diff --git a/PSOProtocol.cc b/src/PSOProtocol.cc similarity index 100% rename from PSOProtocol.cc rename to src/PSOProtocol.cc diff --git a/PSOProtocol.hh b/src/PSOProtocol.hh similarity index 100% rename from PSOProtocol.hh rename to src/PSOProtocol.hh diff --git a/Player.cc b/src/Player.cc similarity index 100% rename from Player.cc rename to src/Player.cc diff --git a/Player.hh b/src/Player.hh similarity index 100% rename from Player.hh rename to src/Player.hh diff --git a/ProxyServer.cc b/src/ProxyServer.cc similarity index 94% rename from ProxyServer.cc rename to src/ProxyServer.cc index 4fafcc44..ca807c96 100644 --- a/ProxyServer.cc +++ b/src/ProxyServer.cc @@ -108,8 +108,8 @@ void ProxyServer::dispatch_on_server_error(struct bufferevent* bev, short events -void ProxyServer::on_listen_accept(struct evconnlistener* listener, - evutil_socket_t fd, struct sockaddr* address, int socklen) { +void ProxyServer::on_listen_accept(struct evconnlistener*, evutil_socket_t fd, + struct sockaddr*, int) { if (this->client_bev.get()) { log(WARNING, "ignoring client connection because client already exists"); @@ -162,15 +162,15 @@ void ProxyServer::on_listen_error(struct evconnlistener* listener) { event_base_loopexit(this->base.get(), NULL); } -void ProxyServer::on_client_input(struct bufferevent* bev) { +void ProxyServer::on_client_input(struct bufferevent*) { this->receive_and_process_commands(false); } -void ProxyServer::on_server_input(struct bufferevent* bev) { +void ProxyServer::on_server_input(struct bufferevent*) { this->receive_and_process_commands(true); } -void ProxyServer::on_client_error(struct bufferevent* bev, short events) { +void ProxyServer::on_client_error(struct bufferevent*, short events) { if (events & BEV_EVENT_ERROR) { int err = EVUTIL_SOCKET_ERROR(); log(WARNING, "error %d (%s) in client stream", err, @@ -190,7 +190,7 @@ void ProxyServer::on_client_error(struct bufferevent* bev, short events) { } } -void ProxyServer::on_server_error(struct bufferevent* bev, short events) { +void ProxyServer::on_server_error(struct bufferevent*, short events) { if (events & BEV_EVENT_ERROR) { int err = EVUTIL_SOCKET_ERROR(); log(WARNING, "error %d (%s) in server stream", err, diff --git a/ProxyServer.hh b/src/ProxyServer.hh similarity index 100% rename from ProxyServer.hh rename to src/ProxyServer.hh diff --git a/ProxyShell.cc b/src/ProxyShell.cc similarity index 100% rename from ProxyShell.cc rename to src/ProxyShell.cc diff --git a/ProxyShell.hh b/src/ProxyShell.hh similarity index 100% rename from ProxyShell.hh rename to src/ProxyShell.hh diff --git a/Quest.cc b/src/Quest.cc similarity index 100% rename from Quest.cc rename to src/Quest.cc diff --git a/Quest.hh b/src/Quest.hh similarity index 100% rename from Quest.hh rename to src/Quest.hh diff --git a/RareItemSet.cc b/src/RareItemSet.cc similarity index 100% rename from RareItemSet.cc rename to src/RareItemSet.cc diff --git a/RareItemSet.hh b/src/RareItemSet.hh similarity index 100% rename from RareItemSet.hh rename to src/RareItemSet.hh diff --git a/ReceiveCommands.cc b/src/ReceiveCommands.cc similarity index 89% rename from ReceiveCommands.cc rename to src/ReceiveCommands.cc index 3be24fc6..5564f59e 100644 --- a/ReceiveCommands.cc +++ b/src/ReceiveCommands.cc @@ -156,7 +156,7 @@ void process_disconnect(shared_ptr s, shared_ptr c) { //////////////////////////////////////////////////////////////////////////////// void process_verify_license_gc(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { // DB + uint16_t, uint32_t, uint16_t size, const void* data) { // DB struct Cmd { char unused[0x20]; char serial_number[0x10]; @@ -192,7 +192,7 @@ void process_verify_license_gc(shared_ptr s, shared_ptr c, } void process_login_a_dc_pc_gc(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { // 9A + uint16_t, uint32_t, uint16_t size, const void* data) { // 9A struct Cmd { char unused[0x20]; char serial_number[0x10]; @@ -232,7 +232,7 @@ void process_login_a_dc_pc_gc(shared_ptr s, shared_ptr c, } void process_login_c_dc_pc_gc(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { // 9C + uint16_t, uint32_t, uint16_t size, const void* data) { // 9C struct Cmd { char unused[8]; uint32_t sub_version; @@ -277,7 +277,7 @@ void process_login_c_dc_pc_gc(shared_ptr s, shared_ptr c, } void process_login_d_e_pc_gc(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { // 9D 9E + uint16_t, uint32_t, uint16_t size, const void* data) { // 9D 9E struct Cmd { char unused[0x10]; uint8_t sub_version; @@ -335,7 +335,7 @@ void process_login_d_e_pc_gc(shared_ptr s, shared_ptr c, } void process_login_bb(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { // 93 + uint16_t, uint32_t, uint16_t size, const void* data) { // 93 struct Cmd { char unused[0x14]; char username[0x10]; @@ -403,13 +403,13 @@ void process_login_bb(shared_ptr s, shared_ptr c, } } -void process_client_checksum(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { // 96 +void process_client_checksum(shared_ptr, shared_ptr c, + uint16_t, uint32_t, uint16_t, const void*) { // 96 send_command(c, 0x97, 0x01); } -void process_server_time_request(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { // B1 +void process_server_time_request(shared_ptr, shared_ptr c, + uint16_t, uint32_t, uint16_t size, const void*) { // B1 check_size(size, 0); send_server_time(c); } @@ -421,7 +421,7 @@ void process_server_time_request(shared_ptr s, shared_ptr c // handlers that partially worked were lost in a dead hard drive, unfortunately. void process_ep3_jukebox(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { + uint16_t command, uint32_t, uint16_t size, const void* data) { struct Cmd { uint32_t unknown[3]; // should be FFFFFFFF 00000000 }; @@ -436,14 +436,14 @@ void process_ep3_jukebox(shared_ptr s, shared_ptr c, send_command(l, command, 0x03, cmd); } -void process_ep3_menu_challenge(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { // DC +void process_ep3_menu_challenge(shared_ptr, shared_ptr c, + uint16_t, uint32_t, uint16_t size, const void*) { // DC check_size(size, 0); send_command(c, 0xDC); } void process_ep3_server_data_request(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { // CA + uint16_t, uint32_t, uint16_t size, const void* data) { // CA check_size(size, 8, 0xFFFF); const PSOSubcommand* cmds = reinterpret_cast(data); @@ -533,7 +533,7 @@ void process_ep3_server_data_request(shared_ptr s, shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { // D6 + uint16_t, uint32_t, uint16_t, const void*) { // D6 if (c->flags & ClientFlag::InInformationMenu) { send_menu(c, u"Information", INFORMATION_MENU_ID, *s->information_menu, false); } else if (c->flags & ClientFlag::AtWelcomeMessage) { @@ -543,7 +543,7 @@ void process_message_box_closed(shared_ptr s, shared_ptr c, } void process_menu_item_info_request(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { // 09 + uint16_t, uint32_t, uint16_t size, const void* data) { // 09 struct Cmd { uint32_t menu_id; uint32_t item_id; @@ -603,7 +603,7 @@ void process_menu_item_info_request(shared_ptr s, shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { // 10 + uint16_t, uint32_t, uint16_t size, const void* data) { // 10 bool uses_unicode = ((c->version == GameVersion::PC) || (c->version == GameVersion::BB)); struct Cmd { @@ -803,7 +803,7 @@ void process_menu_selection(shared_ptr s, shared_ptr c, } void process_change_lobby(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { // 84 + uint16_t, uint32_t, uint16_t size, const void* data) { // 84 struct Cmd { uint32_t menu_id; uint32_t item_id; @@ -828,13 +828,13 @@ void process_change_lobby(shared_ptr s, shared_ptr c, } void process_game_list_request(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { // 08 + uint16_t, uint32_t, uint16_t size, const void*) { // 08 check_size(size, 0); send_game_menu(c, s); } void process_change_ship(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { // A0 + uint16_t, uint32_t, uint16_t, const void*) { // A0 send_message_box(c, u""); // we do this to avoid the "log window in message box" bug static const vector version_to_port_name({ @@ -892,7 +892,7 @@ vector quest_download_menu({ }); void process_quest_list_request(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { // A2 + uint16_t, uint32_t flag, uint16_t size, const void*) { // A2 check_size(size, 0); if (!s->quest_index) { @@ -927,7 +927,7 @@ void process_quest_list_request(shared_ptr s, shared_ptr c, } void process_quest_ready(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { // AC + uint16_t, uint32_t, uint16_t size, const void*) { // AC check_size(size, 0); auto l = s->find_lobby(c->lobby_id); @@ -956,8 +956,8 @@ void process_quest_ready(shared_ptr s, shared_ptr c, } } -void process_gba_file_request(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { // D7 +void process_gba_file_request(shared_ptr, shared_ptr c, + uint16_t, uint32_t, uint16_t size, const void* data) { // D7 static FileContentsCache file_cache; string filename(reinterpret_cast(data), size); @@ -967,8 +967,8 @@ void process_gba_file_request(shared_ptr s, shared_ptr c, send_quest_file(c, filename, *contents, false, false); } -void process_start_download_quest(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { // A6 +void process_start_download_quest(shared_ptr, shared_ptr c, + uint16_t, uint32_t, uint16_t, const void*) { // A6 // TODO implement this send_text_message(c, u"$C6Download quests\nare not supported"); } @@ -979,7 +979,7 @@ void process_start_download_quest(shared_ptr s, shared_ptr // player data commands void process_player_data(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { // 61 98 + uint16_t command, uint32_t, uint16_t size, const void* data) { // 61 98 // note: we add extra buffer on the end when checking sizes because the // autoreply text is a variable length @@ -1095,7 +1095,7 @@ void process_chat_generic(shared_ptr s, shared_ptr c, } void process_chat_pc_bb(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { // 06 + uint16_t, uint32_t, uint16_t size, const void* data) { // 06 struct Cmd { uint32_t unused[2]; char16_t text[0]; @@ -1107,7 +1107,7 @@ void process_chat_pc_bb(shared_ptr s, shared_ptr c, } void process_chat_dc_gc(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { + uint16_t, uint32_t, uint16_t size, const void* data) { struct Cmd { uint32_t unused[2]; char text[0]; @@ -1122,14 +1122,14 @@ void process_chat_dc_gc(shared_ptr s, shared_ptr c, //////////////////////////////////////////////////////////////////////////////// // BB commands -void process_key_config_request_bb(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { +void process_key_config_request_bb(shared_ptr, shared_ptr c, + uint16_t, uint32_t, uint16_t size, const void*) { check_size(size, 0); send_team_and_key_config_bb(c); } -void process_player_preview_request_bb(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { +void process_player_preview_request_bb(shared_ptr, shared_ptr c, + uint16_t, uint32_t, uint16_t size, const void* data) { struct Cmd { uint32_t player_index; uint32_t unused; @@ -1164,8 +1164,8 @@ void process_player_preview_request_bb(shared_ptr s, shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { +void process_client_checksum_bb(shared_ptr, shared_ptr c, + uint16_t command, uint32_t, uint16_t size, const void*) { check_size(size, 0); if (command == 0x01E8) { @@ -1177,8 +1177,8 @@ void process_client_checksum_bb(shared_ptr s, shared_ptr c, } } -void process_guild_card_data_request_bb(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { +void process_guild_card_data_request_bb(shared_ptr, shared_ptr c, + uint16_t, uint32_t, uint16_t size, const void* data) { struct Cmd { uint32_t unknown; uint32_t chunk_index; @@ -1192,8 +1192,8 @@ void process_guild_card_data_request_bb(shared_ptr s, shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { +void process_stream_file_request_bb(shared_ptr, shared_ptr c, + uint16_t command, uint32_t, uint16_t size, const void*) { check_size(size, 0); if (command == 0x04EB) { @@ -1204,7 +1204,7 @@ void process_stream_file_request_bb(shared_ptr s, shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { + uint16_t, uint32_t, uint16_t size, const void* data) { struct Cmd { uint32_t player_index; PlayerDispDataBBPreview preview; @@ -1262,8 +1262,8 @@ void process_create_character_bb(shared_ptr s, shared_ptr c send_approve_player_choice_bb(c); } -void process_change_account_data_bb(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { +void process_change_account_data_bb(shared_ptr, shared_ptr c, + uint16_t command, uint32_t, uint16_t size, const void* data) { union Cmd { uint32_t option; // 01ED uint8_t symbol_chats[0x4E0]; // 02ED @@ -1309,8 +1309,8 @@ void process_change_account_data_bb(shared_ptr s, shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { +void process_return_player_data_bb(shared_ptr, shared_ptr c, + uint16_t, uint32_t, uint16_t size, const void* data) { check_size(size, sizeof(PlayerBB)); const PlayerBB* cmd = reinterpret_cast(data); @@ -1324,7 +1324,7 @@ void process_return_player_data_bb(shared_ptr s, shared_ptr // Lobby commands void process_change_arrow_color(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { // 89 + uint16_t, uint32_t flag, uint16_t size, const void*) { // 89 check_size(size, 0); c->lobby_arrow_color = flag; @@ -1335,7 +1335,7 @@ void process_change_arrow_color(shared_ptr s, shared_ptr c, } void process_card_search(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { // 40 + uint16_t, uint32_t, uint16_t size, const void* data) { // 40 struct Cmd { uint32_t player_tag; uint32_t searcher_serial_number; @@ -1351,13 +1351,13 @@ void process_card_search(shared_ptr s, shared_ptr c, } catch (const out_of_range&) { } } -void process_choice_search(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { // C0 +void process_choice_search(shared_ptr, shared_ptr c, + uint16_t, uint32_t, uint16_t, const void*) { // C0 send_text_message(c, u"$C6Choice Search is\nnot supported"); } void process_simple_mail(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { // 81 + uint16_t, uint32_t, uint16_t size, const void* data) { // 81 if (c->version != GameVersion::GC) { // TODO: implement this for DC, PC, BB send_text_message(c, u"$C6Simple Mail is not\nsupported yet on\nthis platform."); @@ -1386,15 +1386,14 @@ void process_simple_mail(shared_ptr s, shared_ptr c, // if the target has auto-reply enabled, send the autoreply if (target->player.auto_reply[0]) { send_simple_mail(c, target->license->serial_number, - target->player.disp.name, target->player.auto_reply, - sizeof(target->player.auto_reply)); + target->player.disp.name, target->player.auto_reply); } // forward the message string message(cmd->data, strnlen(cmd->data, sizeof(cmd->data) / sizeof(cmd->data[0]))); u16string u16message = decode_sjis(message); send_simple_mail(target, c->license->serial_number, c->player.disp.name, - u16message.data(), u16message.size()); + u16message.data()); } @@ -1403,26 +1402,26 @@ void process_simple_mail(shared_ptr s, shared_ptr c, // Info board commands void process_info_board_request(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { // D8 + uint16_t, uint32_t, uint16_t size, const void*) { // D8 check_size(size, 0); auto l = s->find_lobby(c->lobby_id); send_info_board(c, l); } -void process_write_info_board_pc_bb(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { // D9 +void process_write_info_board_pc_bb(shared_ptr, shared_ptr c, + uint16_t, uint32_t, uint16_t size, const void* data) { // D9 check_size(size, 0, 2 * 0xAC); char16cpy(c->player.info_board, reinterpret_cast(data), 0xAC); } -void process_write_info_board_dc_gc(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { // D9 +void process_write_info_board_dc_gc(shared_ptr, shared_ptr c, + uint16_t, uint32_t, uint16_t size, const void* data) { // D9 check_size(size, 0, 0xAC); decode_sjis(c->player.info_board, reinterpret_cast(data), 0xAC); } -void process_set_auto_reply_pc_bb(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { // C7 +void process_set_auto_reply_pc_bb(shared_ptr, shared_ptr c, + uint16_t, uint32_t, uint16_t size, const void* data) { // C7 check_size(size, 0, 2 * 0xAC); if (size == 0) { c->player.auto_reply[0] = 0; @@ -1431,8 +1430,8 @@ void process_set_auto_reply_pc_bb(shared_ptr s, shared_ptr } } -void process_set_auto_reply_dc_gc(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { // C7 +void process_set_auto_reply_dc_gc(shared_ptr, shared_ptr c, + uint16_t, uint32_t, uint16_t size, const void* data) { // C7 check_size(size, 0, 0xAC); if (size == 0) { c->player.auto_reply[0] = 0; @@ -1441,14 +1440,14 @@ void process_set_auto_reply_dc_gc(shared_ptr s, shared_ptr } } -void process_disable_auto_reply(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { // C8 +void process_disable_auto_reply(shared_ptr, shared_ptr c, + uint16_t, uint32_t, uint16_t size, const void*) { // C8 check_size(size, 0); c->player.auto_reply[0] = 0; } -void process_set_blocked_list(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { // C6 +void process_set_blocked_list(shared_ptr, shared_ptr c, + uint16_t, uint32_t, uint16_t size, const void* data) { // C6 check_size(size, 0x78); memcpy(c->player.blocked, data, 0x78); } @@ -1580,7 +1579,7 @@ shared_ptr create_game_generic(shared_ptr s, } void process_create_game_pc(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { // C1 + uint16_t, uint32_t, uint16_t size, const void* data) { // C1 struct Cmd { uint32_t unused[2]; char16_t name[0x10]; @@ -1602,7 +1601,7 @@ void process_create_game_pc(shared_ptr s, shared_ptr c, } void process_create_game_dc_gc(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { // C1 EC (EC Ep3 only) + uint16_t command, uint32_t, uint16_t size, const void* data) { // C1 EC (EC Ep3 only) struct Cmd { uint32_t unused[2]; char name[0x10]; @@ -1641,7 +1640,7 @@ void process_create_game_dc_gc(shared_ptr s, shared_ptr c, } void process_create_game_bb(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { // C1 + uint16_t, uint32_t, uint16_t size, const void* data) { // C1 struct Cmd { uint32_t unused[2]; char16_t name[0x10]; @@ -1668,7 +1667,7 @@ void process_create_game_bb(shared_ptr s, shared_ptr c, } void process_lobby_name_request(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { // 8A + uint16_t, uint32_t, uint16_t size, const void*) { // 8A check_size(size, 0); auto l = s->find_lobby(c->lobby_id); if (!l) { @@ -1678,7 +1677,7 @@ void process_lobby_name_request(shared_ptr s, shared_ptr c, } void process_client_ready(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { // 6F + uint16_t, uint32_t, uint16_t size, const void*) { // 6F check_size(size, 0); auto l = s->find_lobby(c->lobby_id); @@ -1699,8 +1698,8 @@ void process_client_ready(shared_ptr s, shared_ptr c, //////////////////////////////////////////////////////////////////////////////// // Team commands -void process_team_command_bb(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { // EA +void process_team_command_bb(shared_ptr, shared_ptr c, + uint16_t command, uint32_t, uint16_t, const void*) { // EA if (command == 0x01EA) { send_lobby_message_box(c, u"$C6Teams are not supported."); @@ -1712,14 +1711,14 @@ void process_team_command_bb(shared_ptr s, shared_ptr c, //////////////////////////////////////////////////////////////////////////////// // Patch server commands -void process_encryption_ok_patch(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { +void process_encryption_ok_patch(shared_ptr, shared_ptr c, + uint16_t, uint32_t, uint16_t size, const void*) { check_size(size, 0); send_command(c, 0x04); // this requests the user's login information } void process_login_patch(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { + uint16_t, uint32_t, uint16_t size, const void* data) { struct Cmd { uint32_t unused[3]; char username[0x10]; @@ -1758,11 +1757,11 @@ License check: "; //////////////////////////////////////////////////////////////////////////////// // Command pointer arrays -void process_ignored_command(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { } +void process_ignored_command(shared_ptr, shared_ptr, + uint16_t, uint32_t, uint16_t, const void*) { } -void process_unimplemented_command(shared_ptr s, shared_ptr c, - uint16_t command, uint32_t flag, uint16_t size, const void* data) { +void process_unimplemented_command(shared_ptr, shared_ptr, + uint16_t command, uint32_t flag, uint16_t size, const void*) { log(WARNING, "unknown command: size=%04X command=%04X flag=%08X\n", size, command, flag); throw invalid_argument("unimplemented command"); diff --git a/ReceiveCommands.hh b/src/ReceiveCommands.hh similarity index 100% rename from ReceiveCommands.hh rename to src/ReceiveCommands.hh diff --git a/ReceiveSubcommands.cc b/src/ReceiveSubcommands.cc similarity index 94% rename from ReceiveSubcommands.cc rename to src/ReceiveSubcommands.cc index 36bd592b..eb697624 100644 --- a/ReceiveSubcommands.cc +++ b/src/ReceiveSubcommands.cc @@ -98,7 +98,7 @@ void forward_subcommand(shared_ptr l, shared_ptr c, // Chat commands and the like // client requests to send a guild card -static void process_subcommand_send_guild_card(shared_ptr s, +static void process_subcommand_send_guild_card(shared_ptr, shared_ptr l, shared_ptr c, uint8_t command, uint8_t flag, const PSOSubcommand* p, size_t count) { check_size(count, 9, 0xFFFF); @@ -120,7 +120,7 @@ static void process_subcommand_send_guild_card(shared_ptr s, } // client sends a symbol chat -static void process_subcommand_symbol_chat(shared_ptr s, +static void process_subcommand_symbol_chat(shared_ptr, shared_ptr l, shared_ptr c, uint8_t command, uint8_t flag, const PSOSubcommand* p, size_t count) { check_size(count, 2, 0xFFFF); @@ -133,7 +133,7 @@ static void process_subcommand_symbol_chat(shared_ptr s, } // client sends a word select chat -static void process_subcommand_word_select(shared_ptr s, +static void process_subcommand_word_select(shared_ptr, shared_ptr l, shared_ptr c, uint8_t command, uint8_t flag, const PSOSubcommand* p, size_t count) { check_size(count, 8, 0xFFFF); @@ -161,7 +161,7 @@ static void process_subcommand_word_select(shared_ptr s, // Game commands used by cheat mechanisms // need to process changing areas since we keep track of where players are -static void process_subcommand_change_area(shared_ptr s, +static void process_subcommand_change_area(shared_ptr, shared_ptr l, shared_ptr c, uint8_t command, uint8_t flag, const PSOSubcommand* p, size_t count) { check_size(count, 2, 0xFFFF); @@ -173,7 +173,7 @@ static void process_subcommand_change_area(shared_ptr s, } // when a player is hit by a monster, heal them if infinite HP is enabled -static void process_subcommand_hit_by_monster(shared_ptr s, +static void process_subcommand_hit_by_monster(shared_ptr, shared_ptr l, shared_ptr c, uint8_t command, uint8_t flag, const PSOSubcommand* p, size_t count) { if (!l->is_game() || (p->byte[2] != c->lobby_client_id)) { @@ -186,7 +186,7 @@ static void process_subcommand_hit_by_monster(shared_ptr s, } // when a player casts a tech, restore TP if infinite TP is enabled -static void process_subcommand_use_technique(shared_ptr s, +static void process_subcommand_use_technique(shared_ptr, shared_ptr l, shared_ptr c, uint8_t command, uint8_t flag, const PSOSubcommand* p, size_t count) { if (!l->is_game() || (p->byte[1] != count) || (p->byte[2] != c->lobby_client_id)) { @@ -202,7 +202,7 @@ static void process_subcommand_use_technique(shared_ptr s, // BB Item commands // player drops an item -static void process_subcommand_drop_item(shared_ptr s, +static void process_subcommand_drop_item(shared_ptr, shared_ptr l, shared_ptr c, uint8_t command, uint8_t flag, const PSOSubcommand* p, size_t count) { if (l->version == GameVersion::BB) { @@ -234,7 +234,7 @@ static void process_subcommand_drop_item(shared_ptr s, } // player splits a stack and drops part of it -static void process_subcommand_drop_stacked_item(shared_ptr s, +static void process_subcommand_drop_stacked_item(shared_ptr, shared_ptr l, shared_ptr c, uint8_t command, uint8_t flag, const PSOSubcommand* p, size_t count) { if (l->version == GameVersion::BB) { @@ -269,7 +269,7 @@ static void process_subcommand_drop_stacked_item(shared_ptr s, l->add_item(item); - send_drop_stacked_item(l, c, item.data, cmd->area, cmd->x, cmd->y); + send_drop_stacked_item(l, item.data, cmd->area, cmd->x, cmd->y); } else { forward_subcommand(l, c, command, flag, p, count); @@ -277,7 +277,7 @@ static void process_subcommand_drop_stacked_item(shared_ptr s, } // player requests to pick up an item -static void process_subcommand_pick_up_item(shared_ptr s, +static void process_subcommand_pick_up_item(shared_ptr, shared_ptr l, shared_ptr c, uint8_t command, uint8_t flag, const PSOSubcommand* p, size_t count) { if (l->version == GameVersion::BB) { @@ -310,7 +310,7 @@ static void process_subcommand_pick_up_item(shared_ptr s, } // player equips an item -static void process_subcommand_equip_unequip_item(shared_ptr s, +static void process_subcommand_equip_unequip_item(shared_ptr, shared_ptr l, shared_ptr c, uint8_t command, uint8_t flag, const PSOSubcommand* p, size_t count) { if (l->version == GameVersion::BB) { @@ -333,7 +333,7 @@ static void process_subcommand_equip_unequip_item(shared_ptr s, } } -static void process_subcommand_use_item(shared_ptr s, +static void process_subcommand_use_item(shared_ptr, shared_ptr l, shared_ptr c, uint8_t command, uint8_t flag, const PSOSubcommand* p, size_t count) { if (l->version == GameVersion::BB) { @@ -351,14 +351,14 @@ static void process_subcommand_use_item(shared_ptr s, c->player.inventory.items[index].game_flags &= 0xFFFFFFF7; // unequip } - player_use_item(l, c, index); + player_use_item(c, index); } forward_subcommand(l, c, command, flag, p, count); } static void process_subcommand_open_shop(shared_ptr s, - shared_ptr l, shared_ptr c, uint8_t command, uint8_t flag, + shared_ptr l, shared_ptr c, uint8_t, uint8_t, const PSOSubcommand* p, size_t count) { check_size(count, 2); uint32_t shop_type = p[1].dword; @@ -386,17 +386,17 @@ static void process_subcommand_open_shop(shared_ptr s, } } -static void process_subcommand_open_bank(shared_ptr s, - shared_ptr l, shared_ptr c, uint8_t command, uint8_t flag, - const PSOSubcommand* p, size_t count) { +static void process_subcommand_open_bank(shared_ptr, + shared_ptr l, shared_ptr c, uint8_t, uint8_t, + const PSOSubcommand*, size_t) { if ((l->version == GameVersion::BB) && l->is_game()) { send_bank(c); } } // player performs some bank action -static void process_subcommand_bank_action(shared_ptr s, - shared_ptr l, shared_ptr c, uint8_t command, uint8_t flag, +static void process_subcommand_bank_action(shared_ptr, + shared_ptr l, shared_ptr c, uint8_t, uint8_t, const PSOSubcommand* p, size_t count) { if (l->version == GameVersion::BB) { check_size(count, 4); @@ -456,8 +456,8 @@ static void process_subcommand_bank_action(shared_ptr s, } // player sorts the items in their inventory -static void process_subcommand_sort_inventory(shared_ptr s, - shared_ptr l, shared_ptr c, uint8_t command, uint8_t flag, +static void process_subcommand_sort_inventory(shared_ptr, + shared_ptr l, shared_ptr c, uint8_t, uint8_t, const PSOSubcommand* p, size_t count) { if (l->version == GameVersion::BB) { check_size(count, 31); @@ -635,7 +635,7 @@ static void process_subcommand_box_drop_item(shared_ptr s, } // monster hit by player -static void process_subcommand_monster_hit(shared_ptr s, +static void process_subcommand_monster_hit(shared_ptr, shared_ptr l, shared_ptr c, uint8_t command, uint8_t flag, const PSOSubcommand* p, size_t count) { if (l->version == GameVersion::BB) { @@ -746,7 +746,7 @@ static void process_subcommand_monster_killed(shared_ptr s, } // destroy item (sent when there are too many items on the ground) -static void process_subcommand_destroy_item(shared_ptr s, +static void process_subcommand_destroy_item(shared_ptr, shared_ptr l, shared_ptr c, uint8_t command, uint8_t flag, const PSOSubcommand* p, size_t count) { if (l->version == GameVersion::BB) { @@ -763,7 +763,7 @@ static void process_subcommand_destroy_item(shared_ptr s, } // player requests to tekk an item -static void process_subcommand_identify_item(shared_ptr s, +static void process_subcommand_identify_item(shared_ptr, shared_ptr l, shared_ptr c, uint8_t command, uint8_t flag, const PSOSubcommand* p, size_t count) { if (l->version == GameVersion::BB) { @@ -822,7 +822,7 @@ static void process_subcommand_identify_item(shared_ptr s, //////////////////////////////////////////////////////////////////////////////// -static void process_subcommand_forward_check_size(shared_ptr s, +static void process_subcommand_forward_check_size(shared_ptr, shared_ptr l, shared_ptr c, uint8_t command, uint8_t flag, const PSOSubcommand* p, size_t count) { if (p->byte[1] != count) { @@ -831,7 +831,7 @@ static void process_subcommand_forward_check_size(shared_ptr s, forward_subcommand(l, c, command, flag, p, count); } -static void process_subcommand_forward_check_game(shared_ptr s, +static void process_subcommand_forward_check_game(shared_ptr, shared_ptr l, shared_ptr c, uint8_t command, uint8_t flag, const PSOSubcommand* p, size_t count) { if (!l->is_game()) { @@ -840,7 +840,7 @@ static void process_subcommand_forward_check_game(shared_ptr s, forward_subcommand(l, c, command, flag, p, count); } -static void process_subcommand_forward_check_game_loading(shared_ptr s, +static void process_subcommand_forward_check_game_loading(shared_ptr, shared_ptr l, shared_ptr c, uint8_t command, uint8_t flag, const PSOSubcommand* p, size_t count) { if (!l->is_game() || !l->any_client_loading()) { @@ -849,7 +849,7 @@ static void process_subcommand_forward_check_game_loading(shared_ptr s, +static void process_subcommand_forward_check_size_client(shared_ptr, shared_ptr l, shared_ptr c, uint8_t command, uint8_t flag, const PSOSubcommand* p, size_t count) { if ((p->byte[1] != count) || (p->byte[2] != c->lobby_client_id)) { @@ -858,7 +858,7 @@ static void process_subcommand_forward_check_size_client(shared_ptr forward_subcommand(l, c, command, flag, p, count); } -static void process_subcommand_forward_check_size_game(shared_ptr s, +static void process_subcommand_forward_check_size_game(shared_ptr, shared_ptr l, shared_ptr c, uint8_t command, uint8_t flag, const PSOSubcommand* p, size_t count) { if (!l->is_game() || (p->byte[1] != count)) { @@ -868,8 +868,8 @@ static void process_subcommand_forward_check_size_game(shared_ptr s } // used for invalid commands. normally, clients should be disconnected - to restore this behavior, change the return value back to SUBCOMMAND_ERROR_INVALID_COMMAND. -static void process_subcommand_invalid(shared_ptr s, - shared_ptr l, shared_ptr c, uint8_t command, uint8_t flag, +static void process_subcommand_invalid(shared_ptr, + shared_ptr, shared_ptr, uint8_t command, uint8_t flag, const PSOSubcommand* p, size_t count) { if (command_is_private(command)) { log(WARNING, "invalid subcommand: %02X (%d of them) (private to player %d)", @@ -881,8 +881,8 @@ static void process_subcommand_invalid(shared_ptr s, } // used when an error occurs (unknown commands, etc). normally, clients should be disconnected - to restore this behavior, change the return value back to SUBCOMMAND_ERROR_INVALID_COMMAND. -static void process_subcommand_unimplemented(shared_ptr s, - shared_ptr l, shared_ptr c, uint8_t command, uint8_t flag, +static void process_subcommand_unimplemented(shared_ptr, + shared_ptr, shared_ptr, uint8_t command, uint8_t flag, const PSOSubcommand* p, size_t count) { if (command_is_private(command)) { log(WARNING, "unknown subcommand: %02X (%d of them) (private to player %d)", diff --git a/ReceiveSubcommands.hh b/src/ReceiveSubcommands.hh similarity index 100% rename from ReceiveSubcommands.hh rename to src/ReceiveSubcommands.hh diff --git a/SendCommands.cc b/src/SendCommands.cc similarity index 96% rename from SendCommands.cc rename to src/SendCommands.cc index dc7d7b8b..968aa996 100644 --- a/SendCommands.cc +++ b/src/SendCommands.cc @@ -63,6 +63,7 @@ void send_command(shared_ptr c, uint16_t command, uint32_t flag, send_data.append(reinterpret_cast(data), size); send_data.resize((send_data.size() + 7) & ~7); } + break; } default: @@ -165,7 +166,7 @@ static void send_server_init_gc(shared_ptr c, bool initial_connection) { } static void send_server_init_bb(shared_ptr s, shared_ptr c, - bool initial_connection) { + bool) { struct { char copyright[0x60]; uint8_t server_key[0x30]; @@ -186,7 +187,7 @@ static void send_server_init_bb(shared_ptr s, shared_ptr c, sizeof(cmd.client_key))); } -static void send_server_init_patch(shared_ptr c, bool initial_connection) { +static void send_server_init_patch(shared_ptr c, bool) { struct { char copyright[0x40]; uint32_t server_key; @@ -549,7 +550,7 @@ void send_chat_message(shared_ptr c, uint32_t from_serial_number, } void send_simple_mail_gc(std::shared_ptr c, uint32_t from_serial_number, - const char16_t* from_name, const char16_t* text, size_t max_chars) { + const char16_t* from_name, const char16_t* text) { struct { uint32_t player_tag; uint32_t from_serial_number; @@ -562,15 +563,15 @@ void send_simple_mail_gc(std::shared_ptr c, uint32_t from_serial_number, cmd.from_serial_number = from_serial_number; encode_sjis(cmd.from_name, from_name, sizeof(cmd.from_name) / sizeof(cmd.from_name[0])); cmd.to_serial_number = c->license->serial_number; - encode_sjis(cmd.text, c->player.disp.name, sizeof(cmd.text) / sizeof(cmd.text[0])); + encode_sjis(cmd.text, text, sizeof(cmd.text) / sizeof(cmd.text[0])); send_command(c, 0x81, 0x00, cmd); } void send_simple_mail(std::shared_ptr c, uint32_t from_serial_number, - const char16_t* from_name, const char16_t* text, size_t max_chars) { + const char16_t* from_name, const char16_t* text) { if (c->version == GameVersion::GC) { - send_simple_mail_gc(c, from_serial_number, from_name, text, max_chars); + send_simple_mail_gc(c, from_serial_number, from_name, text); } else { throw logic_error("unimplemented versioned command"); } @@ -1862,8 +1863,8 @@ void send_drop_item(shared_ptr l, const ItemData& item, } // notifies other players that a stack was split and part of it dropped (a new item was created) -void send_drop_stacked_item(shared_ptr l, shared_ptr c, - const ItemData& item, uint8_t area, float x, float y) { +void send_drop_stacked_item(shared_ptr l, const ItemData& item, + uint8_t area, float x, float y) { struct { uint8_t subcommand; uint8_t subsize; @@ -1957,6 +1958,7 @@ void send_shop(shared_ptr c, uint8_t shop_type) { shop_type, static_cast(c->player.current_shop_contents.size()), 0, + {}, }; size_t count = c->player.current_shop_contents.size(); diff --git a/SendCommands.hh b/src/SendCommands.hh similarity index 95% rename from SendCommands.hh rename to src/SendCommands.hh index 4e7fb980..2839b6d7 100644 --- a/SendCommands.hh +++ b/src/SendCommands.hh @@ -106,7 +106,7 @@ void send_text_message(std::shared_ptr l, const char16_t* text); void send_chat_message(std::shared_ptr c, uint32_t from_serial_number, const char16_t* from_name, const char16_t* text); void send_simple_mail(std::shared_ptr c, uint32_t from_serial_number, - const char16_t* from_name, const char16_t* text, size_t max_chars); + const char16_t* from_name, const char16_t* text); template void send_text_message_printf(std::shared_ptr t, const char* format, ...) { @@ -158,8 +158,8 @@ void send_warp(std::shared_ptr c, uint32_t area); void send_drop_item(std::shared_ptr l, const ItemData& item, bool from_enemy, uint8_t area, float x, float y, uint16_t request_id); -void send_drop_stacked_item(std::shared_ptr l, std::shared_ptr c, - const ItemData& item, uint8_t area, float x, float y); +void send_drop_stacked_item(std::shared_ptr l, const ItemData& item, + uint8_t area, float x, float y); void send_pick_up_item(std::shared_ptr l, std::shared_ptr c, uint32_t id, uint8_t area); void send_create_inventory_item(std::shared_ptr l, std::shared_ptr c, diff --git a/Server.cc b/src/Server.cc similarity index 96% rename from Server.cc rename to src/Server.cc index ca64eb60..4f1c7b0a 100644 --- a/Server.cc +++ b/src/Server.cc @@ -85,7 +85,7 @@ void Server::dispatch_on_disconnecting_client_error(struct bufferevent* bev, } void Server::on_listen_accept(struct evconnlistener* listener, - evutil_socket_t fd, struct sockaddr* address, int socklen) { + evutil_socket_t fd, struct sockaddr*, int) { int listen_fd = evconnlistener_get_fd(listener); ListeningSocket* listening_socket; diff --git a/Server.hh b/src/Server.hh similarity index 100% rename from Server.hh rename to src/Server.hh diff --git a/ServerShell.cc b/src/ServerShell.cc similarity index 100% rename from ServerShell.cc rename to src/ServerShell.cc diff --git a/ServerShell.hh b/src/ServerShell.hh similarity index 100% rename from ServerShell.hh rename to src/ServerShell.hh diff --git a/ServerState.cc b/src/ServerState.cc similarity index 100% rename from ServerState.cc rename to src/ServerState.cc diff --git a/ServerState.hh b/src/ServerState.hh similarity index 100% rename from ServerState.hh rename to src/ServerState.hh diff --git a/Shell.cc b/src/Shell.cc similarity index 89% rename from Shell.cc rename to src/Shell.cc index 1826c622..6228a4d9 100644 --- a/Shell.cc +++ b/src/Shell.cc @@ -31,7 +31,7 @@ Shell::Shell(std::shared_ptr base, this->poll.add(0, POLLIN); } -void Shell::dispatch_print_prompt(evutil_socket_t fd, short events, void* ctx) { +void Shell::dispatch_print_prompt(evutil_socket_t, short, void* ctx) { reinterpret_cast(ctx)->print_prompt(); } @@ -39,7 +39,7 @@ void Shell::print_prompt() { // default behavior: no prompt } -void Shell::dispatch_read_stdin(evutil_socket_t fd, short events, void* ctx) { +void Shell::dispatch_read_stdin(evutil_socket_t, short, void* ctx) { reinterpret_cast(ctx)->read_stdin(); } diff --git a/Shell.hh b/src/Shell.hh similarity index 100% rename from Shell.hh rename to src/Shell.hh diff --git a/Text.cc b/src/Text.cc similarity index 100% rename from Text.cc rename to src/Text.cc diff --git a/Text.hh b/src/Text.hh similarity index 100% rename from Text.hh rename to src/Text.hh diff --git a/Version.cc b/src/Version.cc similarity index 100% rename from Version.cc rename to src/Version.cc diff --git a/Version.hh b/src/Version.hh similarity index 100% rename from Version.hh rename to src/Version.hh