├── .gitignore ├── Icarus.sln ├── Icarus.vcxproj ├── Icarus.vcxproj.filters ├── Icarus.vcxproj.user ├── LICENSE.txt ├── README.md ├── compile ├── sql └── icarusdb.sql └── src ├── boot ├── Icarus.cpp └── Icarus.h ├── communication ├── headers │ ├── Incoming.h │ └── Outgoing.h ├── incoming │ ├── DefaultMessageEvent.h │ ├── MessageEvent.h │ ├── MessageHandler.cpp │ ├── MessageHandler.h │ ├── catalogue │ │ ├── CataloguePageMessageEvent.h │ │ ├── CatalogueTabMessageEvent.h │ │ └── PurchaseObjectMessageEvent.h │ ├── item │ │ └── InventoryMessageEvent.h │ ├── login │ │ ├── AuthenticateMessageEvent.h │ │ ├── UniqueIDMessageEvent.h │ │ └── VersionCheckMessageEvent.h │ ├── messenger │ │ ├── FollowFriendMessageEvent.h │ │ ├── MessengerAcceptMessageEvent.h │ │ ├── MessengerDeclineMessageEvent.h │ │ ├── MessengerDeleteFriendMessageEvent.h │ │ ├── MessengerInitMessageEvent.h │ │ ├── MessengerInviteMessageEvent.h │ │ ├── MessengerRequestMessageEvent.h │ │ ├── MessengerSearchMessageEvent.h │ │ ├── MessengerTalkMessageEvent.h │ │ └── MessengerUpdateMessageEvent.h │ ├── misc │ │ ├── EventLogMessageEvent.h │ │ └── LatencyTestMessageEvent.h │ ├── navigator │ │ ├── CanCreateRoomMessageEvent.h │ │ ├── CreateRoomMessageEvent.h │ │ ├── NewNavigatorMessageEvent.h │ │ └── SearchNewNavigatorEvent.h │ ├── room │ │ ├── DeleteRoomMessageEvent.h │ │ ├── EnterRoomMessageEvent.h │ │ ├── HeightMapMessageEvent.h │ │ ├── LeaveRoomMessageEvent.h │ │ ├── RoomEditInfoMessageEvent.h │ │ ├── RoomInfoMessageEvent.h │ │ ├── SaveRoomMessageEvent.h │ │ ├── doorbell │ │ │ ├── AnswerDoorbellMessageEvent.h │ │ │ └── EnterDoorbellMessageEvent.h │ │ ├── item │ │ │ ├── ApplyDecorationMessageEvent.h │ │ │ ├── InteractItemMessageEvent.h │ │ │ ├── MoveItemMessageEvent.h │ │ │ ├── PickupItemMessageEvent.h │ │ │ └── PlaceItemMessageEvent.h │ │ └── user │ │ │ ├── ChatMessageEvent.h │ │ │ ├── DanceMessageEvent.h │ │ │ ├── ShoutMessageEvent.h │ │ │ ├── ShowSignMessageEvent.h │ │ │ ├── TypingStatusMessageEvent.h │ │ │ └── WalkMessageEvent.h │ └── user │ │ ├── CurrencyBalanceMessageEvent.h │ │ └── InfoRetrieveMessageEvent.h ├── outgoing │ ├── DefaultComposer.h │ ├── MessageComposer.h │ ├── catalogue │ │ ├── CataloguePageMessageComposer.h │ │ ├── CatalogueTabMessageComposer.h │ │ ├── PurchaseErrorMessageComposer.h │ │ └── PurchaseNotificationMessageComposer.h │ ├── item │ │ ├── FurniListNotificationComposer.h │ │ ├── InventoryMessageComposer.h │ │ ├── RemoveInventoryItemComposer.h │ │ └── UpdateInventoryMessageComposer.h │ ├── login │ │ ├── AuthenticateMessageComposer.h │ │ ├── AvailabilityMessageComposer.h │ │ ├── HomeRoomMessageComposer.h │ │ ├── LandingWidgetMessageComposer.h │ │ └── UniqueMachineIDMessageComposer.h │ ├── messenger │ │ ├── FollowErrorMessageComposer.h │ │ ├── FollowFriendMessageComposer.h │ │ ├── FriendsListMessageComposer.h │ │ ├── MessageInviteMessageComposer.h │ │ ├── MessengerCategoriesMessageComposer.h │ │ ├── MessengerMessageComposer.h │ │ ├── MessengerRequestsMessageComposer.h │ │ ├── MessengerSearchMessageComposer.h │ │ ├── MessengerSendRequestComposer.h │ │ ├── MessengerUpdateMessageComposer.h │ │ └── RemoveFriendMessageComposer.h │ ├── misc │ │ └── BroadcastMessageAlertComposer.h │ ├── navigator │ │ ├── CanCreateRoomMessageComposer.h │ │ ├── CreateRoomMessageComposer.h │ │ ├── FlatCategoriesMessageComposer.h │ │ ├── NavigatorCategoriesComposer.h │ │ ├── NavigatorMetaDataComposer.h │ │ ├── NavigatorPreferencesMessageComposer.h │ │ └── SearchResultSetComposer.h │ ├── room │ │ ├── RoomDataMessageComposer.h │ │ ├── RoomSettingsDataMessageComposer.h │ │ ├── doorbell │ │ │ ├── AcceptUserInsideRoomMessageComposer.h │ │ │ ├── GenericDoorbellMessageComposer.h │ │ │ ├── GenericErrorMessageComposer.h │ │ │ ├── GenericNoAnswerDoorbellMessageComposer.h │ │ │ └── RoomEnterErrorMessageComposer.h │ │ ├── entry │ │ │ ├── HasOwnerRightsMessageComposer.h │ │ │ ├── NoRightsMessageComposer.h │ │ │ ├── PrepareRoomMessageComposer.h │ │ │ ├── RightsLevelMessageComposer.h │ │ │ ├── RoomModelMessageComposer.h │ │ │ ├── RoomOwnerRightsComposer.h │ │ │ ├── RoomRatingMessageComposer.h │ │ │ └── RoomSpacesMessageComposer.h │ │ ├── item │ │ │ ├── FloorItemsMessageComposer.h │ │ │ ├── MoveItemMessageComposer.h │ │ │ ├── PlaceItemMessageComposer.h │ │ │ ├── RemoveItemMessageComposer.h │ │ │ └── WallItemsMessageComposer.h │ │ ├── model │ │ │ ├── FloorMapMessageComposer.h │ │ │ └── HeightMapMessageComposer.h │ │ └── user │ │ │ ├── DanceStatusMessageComposer.h │ │ │ ├── FloodFilterMessageComposer.h │ │ │ ├── IdleStatusMessageComposer.h │ │ │ ├── RemoveUserMessageComposer.h │ │ │ ├── TalkMessageComposer.h │ │ │ ├── TypingStatusMessageComposer.h │ │ │ ├── UserDisplayMessageComposer.h │ │ │ └── UserStatusMessageComposer.h │ └── user │ │ ├── CreditsMessageComposer.h │ │ ├── HotelViewMessageComposer.h │ │ ├── SendPerkAllowancesMessageComposer.h │ │ └── UserObjectMessageComposer.h └── streams │ ├── Request.cpp │ ├── Request.h │ ├── Response.cpp │ └── Response.h ├── dao ├── CatalogueDao.cpp ├── CatalogueDao.h ├── ItemDao.cpp ├── ItemDao.h ├── MessengerDao.cpp ├── MessengerDao.h ├── MySQLDao.cpp ├── MySQLDao.h ├── NavigatorDao.cpp ├── NavigatorDao.h ├── RoomDao.cpp ├── RoomDao.h ├── UserDao.cpp └── UserDao.h ├── database ├── DatabaseManager.cpp ├── DatabaseManager.h └── lib │ ├── ConnectionPool.h │ └── MySQLConnection.h ├── game ├── Game.cpp ├── Game.h ├── bot │ ├── Bot.cpp │ └── Bot.h ├── catalogue │ ├── CatalogueItem.cpp │ ├── CatalogueItem.h │ ├── CatalogueManager.cpp │ ├── CatalogueManager.h │ ├── CataloguePage.h │ └── CatalogueTab.h ├── entities │ ├── Entity.h │ ├── EntityDetails.cpp │ ├── EntityDetails.h │ └── EntityType.h ├── item │ ├── Item.cpp │ ├── Item.h │ ├── ItemManager.cpp │ ├── ItemManager.h │ ├── definitions │ │ ├── ItemDefinition.h │ │ └── ItemType.h │ ├── interactor │ │ ├── BaseInteractor.h │ │ ├── InteractorManager.cpp │ │ ├── InteractorManager.h │ │ └── interactors │ │ │ ├── DefaultInteractor.h │ │ │ └── GateInteractor.h │ └── inventory │ │ ├── Inventory.cpp │ │ └── Inventory.h ├── messenger │ ├── Messenger.cpp │ ├── Messenger.h │ ├── MessengerUser.cpp │ └── MessengerUser.h ├── navigator │ ├── NavigatorCategory.h │ ├── NavigatorManager.cpp │ ├── NavigatorManager.h │ ├── NavigatorTab.cpp │ ├── NavigatorTab.h │ └── populators │ │ ├── DefaultPopulator.h │ │ ├── DisposablePopulator.h │ │ ├── FriendsPopulator.h │ │ ├── MyRoomPopulator.h │ │ ├── OfficialRoomPopulator.h │ │ ├── PopularPopulator.h │ │ └── RoomPopulator.h ├── pathfinder │ ├── Pathfinder.cpp │ ├── Pathfinder.h │ ├── PathfinderNode.cpp │ ├── PathfinderNode.h │ ├── Position.cpp │ └── Position.h ├── player │ ├── Player.cpp │ ├── Player.h │ ├── PlayerManager.cpp │ └── PlayerManager.h └── room │ ├── Room.cpp │ ├── Room.h │ ├── RoomData.h │ ├── RoomManager.cpp │ ├── RoomManager.h │ ├── RoomUser.cpp │ ├── RoomUser.h │ ├── misc │ ├── RoomNewbie.h │ └── RoomNewbieItem.h │ ├── model │ ├── DynamicModel.cpp │ ├── DynamicModel.h │ ├── RoomModel.cpp │ ├── RoomModel.h │ ├── Rotation.cpp │ ├── Rotation.h │ └── tile │ │ ├── RoomTile.cpp │ │ └── RoomTile.h │ └── tasks │ ├── RoomRunnable.cpp │ └── RoomRunnable.h ├── main.cpp ├── misc ├── Configuration.cpp ├── Configuration.h ├── Utilities.cpp └── Utilities.h ├── network ├── NetworkConnection.cpp ├── NetworkConnection.h ├── NetworkServer.cpp ├── NetworkServer.h └── rcon │ ├── RconConnection.cpp │ ├── RconConnection.h │ ├── RconServer.cpp │ └── RconServer.h ├── stdafx.cpp ├── stdafx.h ├── targetver.h └── thread ├── BlockingQueue.h ├── ExecutorService.cpp ├── ExecutorService.h └── Runnable.h /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Ignore directories # 3 | 4 | Debug/ 5 | Release/ 6 | x64/ 7 | x86/ 8 | .vs/ 9 | Icarus.VC.db 10 | Icarus.VC.VC.opendb 11 | Icarus.sln 12 | Makefile 13 | ipch/ 14 | enc_temp_folder/ 15 | configuration.ini 16 | game.ini 17 | logs/ 18 | config/ -------------------------------------------------------------------------------- /Icarus.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Icarus", "Icarus.vcxproj", "{15FD8BFE-F7D0-49C3-A699-F569761E265E}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {15FD8BFE-F7D0-49C3-A699-F569761E265E}.Debug|x64.ActiveCfg = Debug|x64 17 | {15FD8BFE-F7D0-49C3-A699-F569761E265E}.Debug|x64.Build.0 = Debug|x64 18 | {15FD8BFE-F7D0-49C3-A699-F569761E265E}.Debug|x86.ActiveCfg = Debug|Win32 19 | {15FD8BFE-F7D0-49C3-A699-F569761E265E}.Debug|x86.Build.0 = Debug|Win32 20 | {15FD8BFE-F7D0-49C3-A699-F569761E265E}.Release|x64.ActiveCfg = Release|x64 21 | {15FD8BFE-F7D0-49C3-A699-F569761E265E}.Release|x64.Build.0 = Release|x64 22 | {15FD8BFE-F7D0-49C3-A699-F569761E265E}.Release|x86.ActiveCfg = Release|Win32 23 | {15FD8BFE-F7D0-49C3-A699-F569761E265E}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /Icarus.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | true 5 | 6 | 7 | -hang 8 | WindowsLocalDebugger 9 | 10 | 11 | -hang 12 | WindowsLocalDebugger 13 | 14 | 15 | -hang 16 | WindowsLocalDebugger 17 | 18 | 19 | -hang 20 | WindowsLocalDebugger 21 | $(SolutionDir)$(Platform)\$(Configuration)\ 22 | 23 | -------------------------------------------------------------------------------- /compile: -------------------------------------------------------------------------------- 1 | g++-6 -fpermissive -Wall -Wextra -Wreorder -L /lib64 -I/usr/include/mysql/ -Isrc src/main.cpp src/stdafx.cpp src/boot/Icarus.cpp src/communication/incoming/MessageHandler.cpp src/communication/streams/Request.cpp src/communication/streams/Response.cpp src/dao/CatalogueDao.cpp src/dao/MessengerDao.cpp src/dao/MySQLDao.cpp src/dao/NavigatorDao.cpp src/dao/RoomDao.cpp src/dao/UserDao.cpp src/database/DatabaseManager.cpp src/game/Game.cpp src/game/catalogue/CatalogueManager.cpp src/game/catalogue/CatalogueTab.cpp src/game/messenger/Messenger.cpp src/game/messenger/MessengerUser.cpp src/game/navigator/NavigatorManager.cpp src/game/navigator/NavigatorTab.cpp src/game/navigator/populators/DefaultPopulator.cpp src/game/navigator/populators/MyRoomPopulator.cpp src/game/navigator/populators/OfficialRoomPopulator.cpp src/game/navigator/populators/PopularPopulator.cpp src/game/pathfinder/Pathfinder.cpp src/game/pathfinder/PathfinderNode.cpp src/game/pathfinder/Position.cpp src/game/player/Player.cpp src/game/player/PlayerManager.cpp src/game/room/Room.cpp src/game/room/RoomManager.cpp src/game/room/RoomUser.cpp src/game/room/model/RoomModel.cpp src/game/room/model/Rotation.cpp src/game/room/tasks/RoomRunnable.cpp src/misc/Configuration.cpp src/misc/Utilities.cpp src/network/NetworkConnection.cpp src/network/NetworkServer.cpp src/network/rcon/RconConnection.cpp src/network/rcon/RconServer.cpp src/thread/ExecutorService.cpp -lboost_system -lboost_thread -lboost_filesystem -lpthread -lmysqlcppconn -o icarus -------------------------------------------------------------------------------- /src/boot/Icarus.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include 12 | 13 | #include "game/player/PlayerManager.h" 14 | #include "database/DatabaseManager.h" 15 | #include "network/NetworkServer.h" 16 | #include "communication/incoming/MessageHandler.h" 17 | #include "misc/Configuration.h" 18 | #include "game/Game.h" 19 | 20 | using std::endl; 21 | using std::cout; 22 | 23 | class PlayerManager; 24 | class NetworkServer; 25 | class MessageHandler; 26 | class DatabaseManager; 27 | class Configuration; 28 | class Game; 29 | 30 | class Icarus 31 | { 32 | 33 | public: 34 | ~Icarus(); 35 | static void boot(); 36 | static const long getUnixTimestamp(); 37 | static const int getRandomNumber(int a, int b); 38 | static PlayerManager *getPlayerManager();// { return sessionManager; } 39 | static NetworkServer *getNetworkServer(); 40 | static MessageHandler *getMessageHandler();// { return networkServer; } 41 | static DatabaseManager *getDatabaseManager(); 42 | 43 | static Configuration *getDatabaseConfiguration(); 44 | static Configuration *getGameConfiguration(); 45 | static Configuration *getLogConfiguration(); 46 | static Configuration *getServerConfiguration(); 47 | 48 | static Game *getGame(); 49 | 50 | private: 51 | 52 | static PlayerManager *player_manager; 53 | static NetworkServer *network_server; 54 | static MessageHandler *message_handler; 55 | static DatabaseManager *database_manager; 56 | 57 | static Configuration *server_configuration; 58 | static Configuration *game_configuration; 59 | static Configuration *log_configuration; 60 | static Configuration *database_configuration; 61 | static Game *game; 62 | 63 | 64 | }; 65 | 66 | -------------------------------------------------------------------------------- /src/communication/incoming/DefaultMessageEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/incoming/MessageEvent.h" 11 | 12 | class DefaultMessageEvent : public MessageEvent { 13 | 14 | public: 15 | DefaultMessageEvent() { } 16 | 17 | void handle(Player *player, Request &request) { } 18 | }; -------------------------------------------------------------------------------- /src/communication/incoming/MessageEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "game/player/Player.h" 11 | #include "communication/headers/Outgoing.h" 12 | 13 | #include "communication/streams/Request.h" 14 | #include "communication/streams/Response.h" 15 | 16 | class MessageEvent 17 | { 18 | 19 | public: 20 | virtual ~MessageEvent() {} 21 | virtual void handle(Player *player, Request &request) = 0; 22 | }; -------------------------------------------------------------------------------- /src/communication/incoming/MessageHandler.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | 12 | #include "communication/incoming/MessageEvent.h" 13 | 14 | class Plugin; 15 | class MessageEvent; 16 | class MessageHandler 17 | { 18 | 19 | private: 20 | std::map messages; 21 | 22 | public: 23 | MessageHandler(); 24 | ~MessageHandler(); 25 | void createEvent(int header, MessageEvent *event); 26 | MessageEvent *getMessageEvent(int header); 27 | void invoke(int header, Request &request, Player *player); 28 | static void addObjects(Plugin *plugin); 29 | }; 30 | 31 | -------------------------------------------------------------------------------- /src/communication/incoming/catalogue/CataloguePageMessageEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include "boot/Icarus.h" 12 | #include "game/catalogue/CatalogueTab.h" 13 | 14 | #include "communication/incoming/MessageEvent.h" 15 | #include "communication/outgoing/catalogue/CataloguePageMessageComposer.h" 16 | 17 | class CataloguePageMessageEvent : public MessageEvent { 18 | 19 | public: 20 | CataloguePageMessageEvent() { } 21 | 22 | void handle(Player *player, Request &request) { 23 | 24 | int page_id = request.readInt(); 25 | 26 | CataloguePage *catalogue_page = Icarus::getGame()->getCatalogueManager()->getPage(page_id); 27 | 28 | if (catalogue_page == nullptr) { 29 | return; 30 | } 31 | 32 | player->send(CataloguePageMessageComposer(catalogue_page)); 33 | } 34 | }; -------------------------------------------------------------------------------- /src/communication/incoming/catalogue/CatalogueTabMessageEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "boot/Icarus.h" 11 | #include "game/catalogue/CatalogueTab.h" 12 | 13 | #include "communication/incoming/MessageEvent.h" 14 | #include "communication/outgoing/catalogue/CatalogueTabMessageComposer.h" 15 | 16 | class CatalogueTabMessageEvent : public MessageEvent { 17 | 18 | public: 19 | CatalogueTabMessageEvent() { } 20 | 21 | void handle(Player *player, Request &request) { 22 | 23 | std::string type = request.readString(); 24 | 25 | std::vector parent_tabs = Icarus::getGame()->getCatalogueManager()->getParentTabs(player->getDetails()->rank); 26 | 27 | if (parent_tabs.size() == 0) { 28 | return; 29 | } 30 | 31 | player->send(CatalogueTabMessageComposer(type, parent_tabs, -1, player->getDetails()->rank)); 32 | } 33 | }; -------------------------------------------------------------------------------- /src/communication/incoming/item/InventoryMessageEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/incoming/MessageEvent.h" 11 | #include "communication/outgoing/item/InventoryMessageComposer.h" 12 | 13 | class InventoryMessageEvent : public MessageEvent { 14 | 15 | public: 16 | InventoryMessageEvent() { } 17 | 18 | void handle(Player *player, Request &request) { 19 | player->getInventory()->update(); 20 | } 21 | }; -------------------------------------------------------------------------------- /src/communication/incoming/login/UniqueIDMessageEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/incoming/MessageEvent.h" 11 | #include "communication/outgoing/login/AuthenticateMessageComposer.h" 12 | 13 | #include "dao/UserDao.h" 14 | 15 | class UniqueIDMessageEvent : public MessageEvent { 16 | 17 | public: 18 | UniqueIDMessageEvent() { } 19 | 20 | void handle(Player *player, Request &request) { 21 | 22 | request.readString(); // read junk str 23 | player->setUniqueId(request.readString()); 24 | } 25 | }; -------------------------------------------------------------------------------- /src/communication/incoming/login/VersionCheckMessageEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "boot/Icarus.h" 11 | 12 | #include "communication/incoming/MessageEvent.h" 13 | #include "communication/outgoing/login/AuthenticateMessageComposer.h" 14 | 15 | #include "dao/UserDao.h" 16 | 17 | class VersionCheckMessageEvent : public MessageEvent { 18 | 19 | public: 20 | VersionCheckMessageEvent() { } 21 | 22 | void handle(Player *player, Request &request) { 23 | 24 | std::string revision = request.readString(); 25 | 26 | if (revision == Icarus::getGameConfiguration()->getString("game.revision")) { 27 | return; 28 | } 29 | 30 | // Kick user if they're using incorrect swfs 31 | player->getNetworkConnection()->getSocket().close(); 32 | } 33 | }; -------------------------------------------------------------------------------- /src/communication/incoming/messenger/FollowFriendMessageEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include "game/room/Room.h" 12 | 13 | #include "game/messenger/MessengerUser.h" 14 | #include "communication/incoming/MessageEvent.h" 15 | 16 | #include "communication/outgoing/messenger/FollowFriendMessageComposer.h" 17 | #include "communication/outgoing/messenger/FollowErrorMessageComposer.h" 18 | 19 | class FollowFriendMessageEvent : public MessageEvent { 20 | 21 | public: 22 | FollowFriendMessageEvent() { } 23 | 24 | void handle(Player *player, Request &request) { 25 | 26 | int friend_id = request.readInt(); 27 | int error_id = -1; 28 | 29 | if (!player->getMessenger()->isFriend(friend_id)) { 30 | return; 31 | } 32 | 33 | MessengerUser *client = player->getMessenger()->getFriend(friend_id); 34 | 35 | if (client->isOnline()) { 36 | if (client->getPlayer()->getRoomUser()->in_room) { 37 | player->send(FollowFriendMessageComposer(client->getPlayer()->getRoomUser()->getRoom()->id)); 38 | } 39 | else { 40 | error_id = 2; // User is not in a room 41 | } 42 | 43 | } 44 | else { 45 | error_id = 1; // User is offline 46 | 47 | } 48 | 49 | if (error_id != -1) { 50 | player->send(FollowErrorMessageComposer(error_id)); 51 | } 52 | } 53 | }; -------------------------------------------------------------------------------- /src/communication/incoming/messenger/MessengerAcceptMessageEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include "dao/MessengerDao.h" 12 | #include "game/entities/EntityDetails.h" 13 | 14 | #include "communication/incoming/MessageEvent.h" 15 | #include "communication/outgoing/messenger/MessengerUpdateMessageComposer.h" 16 | 17 | class MessengerAcceptMessageEvent : public MessageEvent { 18 | 19 | public: 20 | MessengerAcceptMessageEvent() { } 21 | 22 | void handle(Player *player, Request &request) { 23 | 24 | int amount = request.readInt(); 25 | 26 | for (int i = 0; i < amount; i++) { 27 | 28 | int to_id = player->getDetails()->id; 29 | int from_id = request.readInt(); 30 | 31 | MessengerDao::removeRequest(from_id, to_id); 32 | MessengerDao::removeRequest(to_id, from_id); 33 | 34 | MessengerDao::newFriend(to_id, from_id); 35 | 36 | MessengerUser *user = new MessengerUser(from_id); 37 | player->getMessenger()->getFriends().insert(std::make_pair(from_id, user)); 38 | 39 | if (user->isOnline()) { 40 | 41 | MessengerUser *to = new MessengerUser(to_id); 42 | 43 | user->getPlayer()->getMessenger()->getFriends().insert(std::make_pair(to_id, to)); 44 | user->getPlayer()->send(MessengerUpdateMessageComposer(to, false)); 45 | } 46 | 47 | player->send(MessengerUpdateMessageComposer(user, false)); 48 | } 49 | 50 | 51 | } 52 | }; -------------------------------------------------------------------------------- /src/communication/incoming/messenger/MessengerDeclineMessageEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include "dao/MessengerDao.h" 12 | #include "communication/incoming/MessageEvent.h" 13 | 14 | class MessengerDeclineMessageEvent : public MessageEvent { 15 | 16 | public: 17 | MessengerDeclineMessageEvent() { } 18 | 19 | void handle(Player *player, Request &request) { 20 | 21 | bool delete_all = request.readBool(); 22 | 23 | if (delete_all) { 24 | 25 | for (auto kvp : player->getMessenger()->getRequests()) { 26 | MessengerDao::removeRequest(kvp.first, player->getDetails()->id); 27 | } 28 | 29 | player->getMessenger()->clearRequests(); 30 | } 31 | else { 32 | 33 | request.readInt(); 34 | int from_id = request.readInt(); 35 | 36 | player->getMessenger()->removeRequest(from_id); 37 | 38 | MessengerDao::removeRequest(from_id, player->getDetails()->id); 39 | } 40 | 41 | } 42 | }; -------------------------------------------------------------------------------- /src/communication/incoming/messenger/MessengerDeleteFriendMessageEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include "game/messenger/MessengerUser.h" 12 | 13 | #include "dao/MessengerDao.h" 14 | 15 | #include "communication/incoming/MessageEvent.h" 16 | #include "communication/outgoing/messenger/RemoveFriendMessageComposer.h" 17 | 18 | class MessengerDeleteFriendMessageEvent: public MessageEvent{ 19 | 20 | public: 21 | MessengerDeleteFriendMessageEvent() { } 22 | 23 | void handle(Player *player, Request &request) { 24 | 25 | int amount = request.readInt(); 26 | 27 | for (int i = 0; i < amount; i++) { 28 | 29 | int friend_id = request.readInt(); 30 | 31 | if (player->getMessenger()->isFriend(friend_id)) { 32 | 33 | MessengerUser *user = player->getMessenger()->getFriend(friend_id); 34 | 35 | if (user->isOnline()) { 36 | user->getPlayer()->getMessenger()->removeFriend(player->getDetails()->id); 37 | user->getPlayer()->send(RemoveFriendMessageComposer(player->getDetails()->id)); 38 | } 39 | 40 | player->getMessenger()->removeFriend(friend_id); 41 | player->send(RemoveFriendMessageComposer(friend_id)); 42 | 43 | MessengerDao::removeFriend(friend_id, player->getDetails()->id); 44 | } 45 | } 46 | } 47 | }; -------------------------------------------------------------------------------- /src/communication/incoming/messenger/MessengerInitMessageEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include "dao/MessengerDao.h" 12 | #include "communication/incoming/MessageEvent.h" 13 | 14 | #include "communication/outgoing/messenger/MessengerMessageComposer.h" 15 | #include "communication/outgoing/messenger/MessengerCategoriesMessageComposer.h" 16 | #include "communication/outgoing/messenger/FriendsListMessageComposer.h" 17 | #include "communication/outgoing/messenger/MessengerRequestsMessageComposer.h" 18 | 19 | class MessengerInitMessageEvent : public MessageEvent { 20 | 21 | public: 22 | MessengerInitMessageEvent() { } 23 | 24 | void handle(Player *player, Request &request) { 25 | 26 | if (player->getMessenger() == nullptr) { 27 | return; 28 | } 29 | 30 | player->send(MessengerCategoriesMessageComposer()); 31 | player->send(FriendsListMessageComposer(player->getMessenger()->getFriends())); 32 | player->send(MessengerRequestsMessageComposer(player->getDetails(), player->getMessenger()->getRequests())); 33 | 34 | std::map offline_messages = MessengerDao::getOfflineMessages(player->getDetails()->id); 35 | 36 | if (offline_messages.size() > 0) { 37 | for (auto kvp : offline_messages) { 38 | player->send(MessengerMessageComposer(kvp.second, kvp.first)); 39 | } 40 | } 41 | 42 | MessengerDao::readMessages(player->getDetails()->id); 43 | 44 | player->getMessenger()->initialised = true; 45 | player->getMessenger()->sendStatus(false); 46 | } 47 | }; -------------------------------------------------------------------------------- /src/communication/incoming/messenger/MessengerInviteMessageEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include "boot/Icarus.h" 12 | #include "misc/Utilities.h" 13 | 14 | #include "communication/incoming/MessageEvent.h" 15 | #include "communication/outgoing/messenger/MessageInviteMessageComposer.h" 16 | 17 | class MessengerInviteMessageEvent : public MessageEvent { 18 | 19 | public: 20 | MessengerInviteMessageEvent() { } 21 | 22 | void handle(Player *player, Request &request) { 23 | 24 | std::vector friends; 25 | 26 | int friend_count = request.readInt(); 27 | 28 | if (friend_count == 0) { 29 | return; 30 | } 31 | 32 | for (int i = 0; i < friend_count; i++) { 33 | 34 | int friend_id = request.readInt(); 35 | 36 | if (Icarus::getPlayerManager()->getPlayerById(friend_id) != nullptr) { 37 | if (player->getMessenger()->isFriend(friend_id)) { 38 | friends.push_back(friend_id); 39 | } 40 | } 41 | } 42 | 43 | std::string invite_message = request.readString(); 44 | invite_message = Utilities::escape(invite_message, true); 45 | 46 | MessageInviteMessageComposer message_compose = MessageInviteMessageComposer(player->getDetails()->id, invite_message); 47 | 48 | for (int friend_id : friends) { 49 | 50 | MessengerUser *messenger_user = player->getMessenger()->getFriend(friend_id); 51 | 52 | if (messenger_user->isOnline()) { 53 | messenger_user->getPlayer()->send(message_compose); 54 | } 55 | } 56 | } 57 | }; -------------------------------------------------------------------------------- /src/communication/incoming/messenger/MessengerRequestMessageEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include "game/messenger/MessengerUser.h" 12 | 13 | #include "dao/UserDao.h" 14 | #include "dao/MessengerDao.h" 15 | 16 | #include "communication/incoming/MessageEvent.h" 17 | #include "communication/outgoing/messenger/MessengerSendRequestComposer.h" 18 | 19 | class MessengerRequestMessageEvent : public MessageEvent { 20 | 21 | public: 22 | MessengerRequestMessageEvent() { } 23 | 24 | void handle(Player *player, Request &request) { 25 | 26 | std::string username = request.readString(); 27 | 28 | if (username.length() < 0) { 29 | return; 30 | } 31 | 32 | int user_id = UserDao::getIdByUsername(username); 33 | 34 | if (user_id < 1) { 35 | return; 36 | } 37 | 38 | if (player->getMessenger()->hasRequest(user_id)) { 39 | return; 40 | } 41 | 42 | if (MessengerDao::newRequest(player->getDetails()->id, user_id)) { 43 | 44 | MessengerUser *user = new MessengerUser(user_id); 45 | player->getMessenger()->getRequests().insert(std::make_pair(user_id, user)); 46 | 47 | if (user->isOnline()) { 48 | user->getPlayer()->send(MessengerSendRequestComposer(player->getDetails())); 49 | } 50 | } 51 | } 52 | }; -------------------------------------------------------------------------------- /src/communication/incoming/messenger/MessengerSearchMessageEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include "dao/MessengerDao.h" 12 | #include "communication/incoming/MessageEvent.h" 13 | #include "communication/outgoing/messenger/MessengerSearchMessageComposer.h" 14 | 15 | class MessengerSearchMessageEvent : public MessageEvent { 16 | 17 | public: 18 | MessengerSearchMessageEvent() { } 19 | 20 | void handle(Player *player, Request &request) { 21 | 22 | std::string searchQuery = request.readString(); 23 | 24 | if (searchQuery.length() < 0) { 25 | return; 26 | } 27 | 28 | Messenger *messenger = player->getMessenger(); 29 | 30 | if (messenger == nullptr) { 31 | return; 32 | } 33 | 34 | if (!messenger->initialised) { 35 | return; 36 | } 37 | 38 | player->send(MessengerSearchMessageComposer(player, MessengerDao::search(searchQuery))); 39 | 40 | } 41 | }; -------------------------------------------------------------------------------- /src/communication/incoming/messenger/MessengerTalkMessageEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include "game/messenger/MessengerUser.h" 12 | #include "communication/incoming/MessageEvent.h" 13 | 14 | #include "dao/MessengerDao.h" 15 | 16 | #include "communication/outgoing/messenger/MessengerMessageComposer.h" 17 | 18 | class MessengerTalkMessageEvent : public MessageEvent { 19 | 20 | public: 21 | MessengerTalkMessageEvent() { } 22 | 23 | void handle(Player *player, Request &request) { 24 | 25 | int friend_id = request.readInt(); 26 | 27 | if (!player->getMessenger()->isFriend(friend_id)) { 28 | return; 29 | } 30 | 31 | MessengerUser *user = player->getMessenger()->getFriend(friend_id); 32 | 33 | std::string message = request.readString(); 34 | message = Utilities::escape(message, true, false); 35 | 36 | 37 | if (message.length() < 1) { 38 | return; 39 | } 40 | 41 | MessengerDao::offlineMessage(friend_id, player->getDetails()->id, message, !user->isOnline()); 42 | 43 | if (user->isOnline()) { 44 | user->getPlayer()->send(MessengerMessageComposer(player->getDetails()->id, message)); 45 | } 46 | } 47 | }; -------------------------------------------------------------------------------- /src/communication/incoming/messenger/MessengerUpdateMessageEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include "dao/MessengerDao.h" 12 | #include "communication/incoming/MessageEvent.h" 13 | 14 | #include "communication/outgoing/messenger/MessengerMessageComposer.h" 15 | #include "communication/outgoing/messenger/MessengerCategoriesMessageComposer.h" 16 | #include "communication/outgoing/messenger/FriendsListMessageComposer.h" 17 | #include "communication/outgoing/messenger/MessengerRequestsMessageComposer.h" 18 | 19 | class MessengerUpdateMessageEvent : public MessageEvent { 20 | 21 | public: 22 | MessengerUpdateMessageEvent() { } 23 | 24 | void handle(Player *player, Request &request) { 25 | cout << "MESSENGER UPDATE!!" << endl; 26 | } 27 | }; -------------------------------------------------------------------------------- /src/communication/incoming/misc/EventLogMessageEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "boot/Icarus.h" 11 | #include "communication/incoming/MessageEvent.h" 12 | 13 | class EventLogMessageEvent : public MessageEvent { 14 | 15 | public: 16 | EventLogMessageEvent() { } 17 | 18 | void handle(Player *player, Request &request) { 19 | 20 | /* if (!player->getNetworkConnection()->isDataSent()) { 21 | Icarus::getMessageHandler()->invoke(Incoming::NewNavigatorMessageEvent, request, player); 22 | Icarus::getMessageHandler()->invoke(Incoming::MessengerInitMessageEvent, request, player); 23 | Icarus::getMessageHandler()->invoke(Incoming::UserDataMessageEvent, request, player); 24 | }*/ 25 | 26 | } 27 | }; -------------------------------------------------------------------------------- /src/communication/incoming/misc/LatencyTestMessageEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "boot/Icarus.h" 11 | #include "communication/incoming/MessageEvent.h" 12 | #include "communication/outgoing/messenger/MessengerUpdateMessageComposer.h" 13 | 14 | class LatencyTestMessageEvent : public MessageEvent { 15 | 16 | public: 17 | LatencyTestMessageEvent() { } 18 | 19 | void handle(Player *player, Request &request) { 20 | 21 | /*if (player->getMessenger() != nullptr) { 22 | 23 | if (!player->getMessenger()->isInitialised()) { 24 | player->getMessenger()->setInitialised(true); 25 | } 26 | 27 | for (auto kvp : player->getMessenger()->getFriends()) { 28 | player->send(MessengerUpdateMessageComposer(kvp.second, false)); 29 | } 30 | }*/ 31 | } 32 | }; -------------------------------------------------------------------------------- /src/communication/incoming/navigator/CanCreateRoomMessageEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/incoming/MessageEvent.h" 11 | 12 | #include "communication/outgoing/navigator/CanCreateRoomMessageComposer.h" 13 | 14 | #include "dao/NavigatorDao.h" 15 | 16 | class CanCreateRoomMessageEvent : public MessageEvent { 17 | 18 | public: 19 | CanCreateRoomMessageEvent() { } 20 | 21 | void handle(Player *player, Request &request) { 22 | player->send(CanCreateRoomMessageComposer(player)); 23 | 24 | } 25 | }; -------------------------------------------------------------------------------- /src/communication/incoming/navigator/NewNavigatorMessageEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "boot/Icarus.h" 11 | #include "communication/incoming/MessageEvent.h" 12 | #include "communication/outgoing/navigator/FlatCategoriesMessageComposer.h" 13 | #include "communication/outgoing/navigator/NavigatorCategoriesComposer.h" 14 | #include "communication/outgoing/navigator/NavigatorMetaDataComposer.h" 15 | #include "communication/outgoing/navigator/NavigatorPreferencesMessageComposer.h" 16 | 17 | #include "communication/outgoing/user/CreditsMessageComposer.h" 18 | #include "communication/outgoing/user/UserObjectMessageComposer.h" 19 | #include "communication/outgoing/user/SendPerkAllowancesMessageComposer.h" 20 | 21 | class NewNavigatorMessageEvent : public MessageEvent { 22 | 23 | public: 24 | NewNavigatorMessageEvent() { } 25 | 26 | void handle(Player *player, Request &request) { 27 | 28 | player->send(FlatCategoriesMessageComposer(Icarus::getGame()->getNavigatorManager()->getCategories(), player->getDetails()->rank)); 29 | player->send(NavigatorCategoriesComposer(Icarus::getGame()->getNavigatorManager()->getCategories())); 30 | player->send(NavigatorMetaDataComposer()); 31 | player->send(NavigatorPreferencesMessageComposer()); 32 | } 33 | }; -------------------------------------------------------------------------------- /src/communication/incoming/navigator/SearchNewNavigatorEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "boot/Icarus.h" 11 | #include "game/navigator/NavigatorTab.h" 12 | #include "communication/incoming/MessageEvent.h" 13 | #include "communication/outgoing/navigator/SearchResultSetComposer.h" 14 | 15 | class SearchNewNavigatorEvent : public MessageEvent { 16 | 17 | public: 18 | SearchNewNavigatorEvent() { } 19 | 20 | void handle(Player *player, Request &request) { 21 | 22 | std::string tab = request.readString(); 23 | std::string query = request.readString(); 24 | 25 | NavigatorTab *navigator_tab = Icarus::getGame()->getNavigatorManager()->getTab(tab); 26 | 27 | if (navigator_tab == nullptr) { 28 | return; 29 | } 30 | 31 | player->send(SearchResultSetComposer(player, navigator_tab, query)); 32 | } 33 | }; -------------------------------------------------------------------------------- /src/communication/incoming/room/DeleteRoomMessageEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include "communication/incoming/MessageEvent.h" 12 | #include "dao/RoomDao.h" 13 | 14 | class DeleteRoomMessageEvent : public MessageEvent { 15 | 16 | public: 17 | DeleteRoomMessageEvent() { } 18 | 19 | void handle(Player *player, Request &request) { 20 | 21 | if (!player->getRoomUser()->in_room) { 22 | return; 23 | } 24 | 25 | Room *room = player->getRoomUser()->getRoom(); 26 | 27 | if (!room->hasRights(player, true)) { 28 | return; 29 | } 30 | 31 | room->kickPlayers(); 32 | 33 | // TODO: Put furniture back into peoples inventories 34 | 35 | // Delete room from database 36 | RoomDao::deleteRoom(room->id); 37 | 38 | // Delete room information 39 | room->dispose(true); 40 | } 41 | }; -------------------------------------------------------------------------------- /src/communication/incoming/room/LeaveRoomMessageEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/incoming/MessageEvent.h" 11 | 12 | class LeaveRoomMessageEvent : public MessageEvent { 13 | 14 | public: 15 | LeaveRoomMessageEvent() { } 16 | 17 | void handle(Player *player, Request &request) { 18 | player->getRoomUser()->leaveRoom(); 19 | } 20 | }; -------------------------------------------------------------------------------- /src/communication/incoming/room/RoomEditInfoMessageEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include "game/room/Room.h" 12 | 13 | #include "game/messenger/MessengerUser.h" 14 | #include "communication/incoming/MessageEvent.h" 15 | 16 | #include "communication/outgoing/room/RoomSettingsDataMessageComposer.h" 17 | 18 | class RoomEditInfoMessageEvent : public MessageEvent { 19 | 20 | public: 21 | RoomEditInfoMessageEvent() { } 22 | 23 | void handle(Player *player, Request &request) { 24 | 25 | if (!player->getRoomUser()->in_room) { 26 | return; 27 | } 28 | 29 | Room *room = player->getRoomUser()->getRoom(); 30 | 31 | if (!room->hasRights(player, true)) { 32 | return; 33 | } 34 | 35 | player->send(RoomSettingsDataMessageComposer(room)); 36 | } 37 | }; -------------------------------------------------------------------------------- /src/communication/incoming/room/RoomInfoMessageEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include "dao/RoomDao.h" 12 | 13 | #include "communication/incoming/MessageEvent.h" 14 | #include "communication/outgoing/room/RoomDataMessageComposer.h" 15 | 16 | class RoomInfoMessageEvent : public MessageEvent { 17 | 18 | public: 19 | RoomInfoMessageEvent() { } 20 | 21 | void handle(Player *player, Request &request) { 22 | 23 | int room_id = request.readInt(); 24 | 25 | Room *room = Icarus::getGame()->getRoomManager()->getRoom(room_id); 26 | 27 | if (room == nullptr) { 28 | return; 29 | } 30 | 31 | int is_loading = request.readInt(); 32 | int check_entry = request.readInt(); 33 | 34 | player->send(RoomDataMessageComposer(room, player, is_loading == 1, check_entry == 1)); 35 | } 36 | }; -------------------------------------------------------------------------------- /src/communication/incoming/room/doorbell/AnswerDoorbellMessageEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include "boot/Icarus.h" 12 | 13 | #include "communication/outgoing/room/doorbell/GenericNoAnswerDoorbellMessageComposer.h" 14 | #include "communication/outgoing/room/doorbell/AcceptUserInsideRoomMessageComposer.h" 15 | #include "communication/outgoing/user/HotelViewMessageComposer.h" 16 | 17 | #include "communication/incoming/MessageEvent.h" 18 | 19 | class AnswerDoorbellMessageEvent : public MessageEvent { 20 | 21 | public: 22 | AnswerDoorbellMessageEvent() { } 23 | 24 | void handle(Player *player, Request &request) { 25 | 26 | Room *room = player->getRoomUser()->getRoom(); 27 | 28 | if (room == nullptr) { 29 | return; 30 | } 31 | 32 | std::string name = request.readString(); 33 | bool accept = request.readBool(); 34 | 35 | if (name.length() < 1) { 36 | return; 37 | } 38 | 39 | Player *client = Icarus::getPlayerManager()->getPlayerByUsername(name); 40 | 41 | if (client == nullptr) { 42 | return; 43 | } 44 | 45 | if (!client->authenticated()) { 46 | return; 47 | } 48 | 49 | if (!accept) { 50 | client->send(GenericNoAnswerDoorbellMessageComposer()); 51 | player->getRoomUser()->leaveRoom(); 52 | } 53 | else { 54 | client->send(AcceptUserInsideRoomMessageComposer()); 55 | } 56 | 57 | } 58 | }; -------------------------------------------------------------------------------- /src/communication/incoming/room/doorbell/EnterDoorbellMessageEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include "boot/Icarus.h" 12 | 13 | #include "communication/outgoing/room/RoomDataMessageComposer.h" 14 | 15 | #include "dao/RoomDao.h" 16 | 17 | class EnterDoorbellMessageEvent : public MessageEvent { 18 | 19 | public: 20 | EnterDoorbellMessageEvent() { } 21 | 22 | void handle(Player *player, Request &request) { 23 | 24 | int room_id = request.readInt(); 25 | 26 | player->getRoomUser()->leaveRoom(false); 27 | 28 | Room *room = Icarus::getGame()->getRoomManager()->getRoom(room_id); 29 | 30 | if (room == nullptr) { 31 | 32 | room = RoomDao::getRoom(room_id); 33 | 34 | if (room != nullptr) { 35 | Icarus::getGame()->getRoomManager()->addRoom(room); 36 | } 37 | else { 38 | return; 39 | } 40 | } 41 | 42 | room->enter(player); // call method to finalise enter room 43 | player->send(RoomDataMessageComposer(room, player, true, false)); 44 | } 45 | }; -------------------------------------------------------------------------------- /src/communication/incoming/room/item/InteractItemMessageEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include "game/item/Item.h" 12 | #include "game/room/Room.h" 13 | 14 | #include "game/item/interactor/BaseInteractor.h" 15 | 16 | #include "communication/incoming/MessageEvent.h" 17 | 18 | class InteractItemMessageEvent : public MessageEvent { 19 | 20 | public: 21 | InteractItemMessageEvent() { } 22 | 23 | void handle(Player *player, Request &request) { 24 | 25 | 26 | if (!player->getRoomUser()->in_room) { 27 | return; 28 | } 29 | 30 | Room *room = player->getRoomUser()->getRoom(); 31 | 32 | if (!room->hasRights(player)) { 33 | return; 34 | } 35 | 36 | int item_id = request.readInt(); 37 | 38 | Item *item = room->getItem(item_id); 39 | 40 | if (item == nullptr) { 41 | return; 42 | } 43 | 44 | BaseInteractor *interactor = item->getInteractor(); 45 | 46 | if (interactor != nullptr) { 47 | interactor->onInteract(room, item); 48 | } 49 | } 50 | }; -------------------------------------------------------------------------------- /src/communication/incoming/room/item/MoveItemMessageEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/incoming/MessageEvent.h" 11 | 12 | #include "game/item/Item.h" 13 | #include "game/room/Room.h" 14 | 15 | class MoveItemMessageEvent : public MessageEvent { 16 | 17 | public: 18 | MoveItemMessageEvent() { } 19 | 20 | void handle(Player *player, Request &request) { 21 | 22 | if (!player->getRoomUser()->in_room) { 23 | return; 24 | } 25 | 26 | Room *room = player->getRoomUser()->getRoom(); 27 | 28 | if (!room->hasRights(player)) { 29 | return; 30 | } 31 | 32 | int item_id = request.readInt(); 33 | 34 | Item *item = room->getItem(item_id); 35 | 36 | if (item == nullptr) { 37 | return; 38 | } 39 | 40 | bool rotation_only = false; 41 | 42 | if (item->isFloorItem()) { 43 | 44 | int x = request.readInt(); 45 | int y = request.readInt(); 46 | int rotation = request.readInt(); 47 | 48 | if (x == item->x && item->y == y) { 49 | rotation_only = true; 50 | } 51 | 52 | item->x = x; 53 | item->y = y; 54 | item->rotation = rotation; 55 | } 56 | 57 | if (item->isWallItem()) { 58 | std::string input = request.readString(); 59 | std::vector pos = Utilities::split(Utilities::split(input, ':')[1], ' '); 60 | item->parseWallPosition(pos[2] + "," + pos[0].substr(2) + " " + pos[1].substr(2)); 61 | 62 | } 63 | 64 | room->getDynamicModel()->updateItemPosition(item, rotation_only); 65 | } 66 | }; -------------------------------------------------------------------------------- /src/communication/incoming/room/item/PickupItemMessageEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/incoming/MessageEvent.h" 11 | 12 | #include "game/item/Item.h" 13 | #include "game/room/Room.h" 14 | 15 | #include "game/item/inventory/Inventory.h" 16 | 17 | class PickupItemMessageEvent : public MessageEvent { 18 | 19 | public: 20 | PickupItemMessageEvent() { } 21 | 22 | void handle(Player *player, Request &request) { 23 | 24 | if (!player->getRoomUser()->in_room) { 25 | return; 26 | } 27 | 28 | int unknown = request.readInt(); 29 | int item_id = request.readInt(); 30 | 31 | Room *room = player->getRoomUser()->getRoom(); 32 | Item *item = room->getItem(item_id); 33 | 34 | if (item == nullptr) { 35 | return; 36 | } 37 | 38 | bool can_pickup = false; 39 | 40 | if (room->hasRights(player)) { 41 | can_pickup = true; 42 | } 43 | 44 | if (item->owner_id == player->getDetails()->id) { 45 | can_pickup = true; 46 | } 47 | 48 | if (player->hasFuse("room_item_take")) { 49 | can_pickup = true; 50 | } 51 | 52 | if (!can_pickup) { 53 | return; 54 | } 55 | 56 | if (item->isFloorItem()) { 57 | item->x = -1; 58 | item->x = -1; 59 | item->updateEntities(); 60 | } 61 | 62 | item->user_id = player->getDetails()->id; 63 | room->getDynamicModel()->removeItem(item); 64 | 65 | player->getInventory()->addItem(item); 66 | player->getInventory()->update(); 67 | } 68 | }; -------------------------------------------------------------------------------- /src/communication/incoming/room/item/PlaceItemMessageEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include "misc/Utilities.h" 12 | 13 | #include "game/room/Room.h" 14 | #include "game/item/Item.h" 15 | 16 | #include "communication/incoming/MessageEvent.h" 17 | 18 | class PlaceItemMessageEvent : public MessageEvent { 19 | 20 | public: 21 | PlaceItemMessageEvent() { } 22 | 23 | void handle(Player *player, Request &request) { 24 | 25 | if (!player->getRoomUser()->in_room) { 26 | return; 27 | } 28 | 29 | Room *room = player->getRoomUser()->getRoom(); 30 | 31 | if (!room->hasRights(player)) { 32 | return; 33 | } 34 | 35 | std::string input = request.readString(); 36 | 37 | std::vector data = Utilities::split(input, ' '); 38 | int item_id = stoi(Utilities::replaceChar(data[0], '-', ' ')); 39 | 40 | Item *item = player->getInventory()->getItem(item_id); 41 | 42 | if (item == nullptr) { 43 | return; 44 | } 45 | 46 | if (item->isFloorItem()) { 47 | 48 | int x = stoi(data[1]); 49 | int y = stoi(data[2]); 50 | int rotation = stoi(data[3]); 51 | 52 | item->x = x; 53 | item->y = y; 54 | item->rotation = rotation; 55 | } 56 | 57 | if (item->isWallItem()) { 58 | 59 | // :w=0,10 l=13,37 l 60 | 61 | std::vector pos = Utilities::split(Utilities::split(input, ':')[1], ' '); 62 | item->parseWallPosition(pos[2] + "," + pos[0].substr(2) + " " + pos[1].substr(2)); 63 | } 64 | 65 | player->getInventory()->removeItem(item, false); 66 | room->getDynamicModel()->addItem(item); 67 | 68 | } 69 | }; -------------------------------------------------------------------------------- /src/communication/incoming/room/user/ChatMessageEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/incoming/MessageEvent.h" 11 | 12 | class ChatMessageEvent : public MessageEvent { 13 | 14 | public: 15 | ChatMessageEvent() { } 16 | 17 | void handle(Player *player, Request &request) { 18 | 19 | if (!player->getRoomUser()->in_room) { 20 | return; 21 | } 22 | 23 | RoomUser *room_user = player->getRoomUser(); 24 | room_user->awake(); 25 | 26 | std::string message = request.readString(); 27 | int bubble = request.readInt(); 28 | int count = request.readInt(); 29 | 30 | 31 | player->getRoomUser()->chat(message, bubble, count, false, true); 32 | } 33 | }; -------------------------------------------------------------------------------- /src/communication/incoming/room/user/DanceMessageEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include "game/room/Room.h" 12 | 13 | #include "communication/incoming/MessageEvent.h" 14 | #include "communication/outgoing/room/user/DanceStatusMessageComposer.h" 15 | 16 | class DanceMessageEvent : public MessageEvent { 17 | 18 | public: 19 | DanceMessageEvent() { } 20 | 21 | void handle(Player *player, Request &request) { 22 | 23 | if (!player->getRoomUser()->in_room) { 24 | return; 25 | } 26 | 27 | RoomUser *room_user = player->getRoomUser(); 28 | room_user->awake(); 29 | 30 | int dance_id = request.readInt(); 31 | 32 | if (dance_id < 0 || dance_id > 4) 33 | dance_id = 0; 34 | 35 | room_user->dance_id = dance_id; 36 | room_user->getRoom()->send(DanceStatusMessageComposer(room_user->virtual_id, dance_id)); 37 | } 38 | }; -------------------------------------------------------------------------------- /src/communication/incoming/room/user/ShoutMessageEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/incoming/MessageEvent.h" 11 | 12 | class ShoutMessageEvent : public MessageEvent { 13 | 14 | public: 15 | ShoutMessageEvent() { } 16 | 17 | void handle(Player *player, Request &request) { 18 | 19 | if (!player->getRoomUser()->in_room) { 20 | return; 21 | } 22 | 23 | RoomUser *room_user = player->getRoomUser(); 24 | room_user->awake(); 25 | 26 | std::string message = request.readString(); 27 | int bubble = request.readInt(); 28 | int count = request.readInt(); 29 | 30 | player->getRoomUser()->chat(message, bubble, count, true, true); 31 | } 32 | }; -------------------------------------------------------------------------------- /src/communication/incoming/room/user/ShowSignMessageEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include "boot/Icarus.h" 12 | 13 | #include "communication/incoming/MessageEvent.h" 14 | 15 | class ShowSignMessageEvent : public MessageEvent { 16 | 17 | public: 18 | ShowSignMessageEvent() { } 19 | 20 | void handle(Player *player, Request &request) { 21 | 22 | if (!player->getRoomUser()->in_room) { 23 | return; 24 | } 25 | 26 | RoomUser *room_user = player->getRoomUser(); 27 | room_user->awake(); 28 | 29 | int sign_id = request.readInt(); 30 | 31 | if (sign_id > 17) { 32 | return; 33 | } 34 | 35 | room_user->setStatus("sign", std::to_string(sign_id)); 36 | room_user->sign_time = Icarus::getUnixTimestamp() + 5; 37 | room_user->updateStatus(); 38 | } 39 | }; -------------------------------------------------------------------------------- /src/communication/incoming/room/user/TypingStatusMessageEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include "game/room/Room.h" 12 | 13 | #include "communication/headers/Incoming.h" 14 | 15 | #include "communication/outgoing/room/user/TypingStatusMessageComposer.h" 16 | #include "communication/incoming/MessageEvent.h" 17 | 18 | class TypingStatusMessageEvent : public MessageEvent { 19 | 20 | public: 21 | TypingStatusMessageEvent() { } 22 | 23 | void handle(Player *player, Request &request) { 24 | 25 | RoomUser *room_user = player->getRoomUser(); 26 | 27 | if (!room_user->in_room) { 28 | return; 29 | } 30 | 31 | room_user->awake(); 32 | room_user->getRoom()->send(TypingStatusMessageComposer(room_user->virtual_id, request.getMessageId() == Incoming::StartTypingMessageEvent)); 33 | } 34 | }; -------------------------------------------------------------------------------- /src/communication/incoming/room/user/WalkMessageEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include "communication/incoming/MessageEvent.h" 12 | #include "game/pathfinder/Pathfinder.h" 13 | 14 | class WalkMessageEvent : public MessageEvent { 15 | 16 | public: 17 | WalkMessageEvent() { } 18 | 19 | void handle(Player *player, Request &request) { 20 | 21 | Room *room = player->getRoomUser()->getRoom(); 22 | 23 | if (room == nullptr) { 24 | return; 25 | } 26 | 27 | int goal_x = request.readInt(); 28 | int goal_y = request.readInt(); 29 | 30 | RoomUser *room_user = player->getRoomUser(); 31 | room_user->awake(); 32 | 33 | room_user->goal.x = goal_x; 34 | room_user->goal.y = goal_y; 35 | 36 | Position goal = room_user->goal; 37 | Position current = room_user->position; 38 | 39 | if (goal.x == current.x && goal.y == current.y) { 40 | return; 41 | } 42 | 43 | auto path = Pathfinder::makePath(room_user->position, room_user->goal, room); 44 | 45 | if (path.size() == 0) { 46 | return; 47 | } 48 | 49 | room_user->setPath(path); 50 | room_user->is_walking = true; 51 | } 52 | }; -------------------------------------------------------------------------------- /src/communication/incoming/user/CurrencyBalanceMessageEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/incoming/MessageEvent.h" 11 | #include "communication/outgoing/user/CreditsMessageComposer.h" 12 | 13 | class CurrencyBalanceMessageEvent : public MessageEvent { 14 | 15 | public: 16 | CurrencyBalanceMessageEvent() { } 17 | 18 | void handle(Player *player, Request &request) { 19 | 20 | player->send(CreditsMessageComposer(player->getDetails()->credits)); 21 | } 22 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/DefaultComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/outgoing/MessageComposer.h" 11 | 12 | class DefaultComposer : public MessageComposer { 13 | 14 | public: 15 | DefaultComposer() { } 16 | 17 | const Response compose() const { 18 | Response response = this->createResponse(); 19 | return response; 20 | } 21 | 22 | const int getHeader() const { 23 | return Outgoing::AuthenticationOKMessageComposer; 24 | } 25 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/MessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/headers/Outgoing.h" 11 | 12 | #include "communication/streams/Request.h" 13 | #include "communication/streams/Response.h" 14 | 15 | class MessageComposer 16 | { 17 | 18 | public: 19 | virtual ~MessageComposer() {} 20 | virtual const Response compose() const = 0; 21 | virtual const int getHeader() const = 0; 22 | const Response createResponse() const { return Response(this->getHeader()); } 23 | 24 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/catalogue/PurchaseErrorMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/outgoing/MessageComposer.h" 11 | 12 | class PurchaseErrorMessageComposer : public MessageComposer { 13 | 14 | public: 15 | PurchaseErrorMessageComposer(bool credits_error, bool pixel_error) : 16 | credits_error(credits_error), 17 | pixel_error(pixel_error) { } 18 | 19 | const Response compose() const { 20 | Response response = this->createResponse(); 21 | response.writeBool(this->credits_error); 22 | response.writeBool(this->pixel_error); 23 | return response; 24 | } 25 | 26 | const int getHeader() const { 27 | return Outgoing::PurchaseErrorMessageComposer; 28 | } 29 | 30 | private: 31 | bool credits_error; 32 | bool pixel_error; 33 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/catalogue/PurchaseNotificationMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "game/catalogue/CatalogueItem.h" 11 | #include "communication/outgoing/MessageComposer.h" 12 | 13 | class PurchaseNotificationMessageComposer : public MessageComposer { 14 | 15 | public: 16 | PurchaseNotificationMessageComposer(CatalogueItem *item, int amount) : 17 | item(item), 18 | amount(amount) { } 19 | 20 | const Response compose() const { 21 | Response response = this->createResponse(); 22 | item->serialise(response); 23 | return response; 24 | } 25 | 26 | const int getHeader() const { 27 | return Outgoing::PurchaseNotificationMessageComposer; 28 | } 29 | 30 | private: 31 | CatalogueItem *item; 32 | int amount; 33 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/item/FurniListNotificationComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include "game/item/Item.h" 12 | 13 | #include "communication/outgoing/MessageComposer.h" 14 | 15 | class FurniListNotificationComposer : public MessageComposer { 16 | 17 | public: 18 | FurniListNotificationComposer(int item_id, int type) : 19 | item_id(item_id), 20 | type(type){ } 21 | 22 | const Response compose() const { 23 | Response response = this->createResponse(); 24 | response.writeInt(1); 25 | response.writeInt(type); 26 | response.writeInt(1); 27 | response.writeInt(item_id); 28 | return response; 29 | } 30 | 31 | const int getHeader() const { 32 | return Outgoing::FurniListNotificationComposer; 33 | } 34 | 35 | private: 36 | int item_id; 37 | int type; 38 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/item/RemoveInventoryItemComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/outgoing/MessageComposer.h" 11 | 12 | class RemoveInventoryItemComposer : public MessageComposer { 13 | 14 | public: 15 | RemoveInventoryItemComposer(int id) : 16 | id(id) { } 17 | 18 | const Response compose() const { 19 | Response response = this->createResponse(); 20 | response.writeInt(this->id); 21 | return response; 22 | } 23 | 24 | const int getHeader() const { 25 | return Outgoing::RemoveInventoryItemComposer; 26 | } 27 | 28 | private: 29 | int id; 30 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/item/UpdateInventoryMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/outgoing/MessageComposer.h" 11 | 12 | class UpdateInventoryMessageComposer : public MessageComposer { 13 | 14 | public: 15 | UpdateInventoryMessageComposer() { } 16 | 17 | const Response compose() const { 18 | Response response = this->createResponse(); 19 | return response; 20 | } 21 | 22 | const int getHeader() const { 23 | return Outgoing::UpdateInventoryMessageComposer; 24 | } 25 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/login/AuthenticateMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/outgoing/MessageComposer.h" 11 | 12 | class AuthenticateMessageComposer : public MessageComposer { 13 | 14 | public: 15 | AuthenticateMessageComposer() { } 16 | 17 | const Response compose() const { 18 | Response response(this->getHeader()); 19 | return response; 20 | } 21 | 22 | const int getHeader() const { 23 | return Outgoing::AuthenticationOKMessageComposer; 24 | } 25 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/login/AvailabilityMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/outgoing/MessageComposer.h" 11 | 12 | class AvailabilityMessageComposer : public MessageComposer { 13 | 14 | public: 15 | AvailabilityMessageComposer() { } 16 | 17 | const Response compose() const { 18 | Response response = this->createResponse(); 19 | response.writeBool(true); 20 | response.writeBool(false); 21 | response.writeBool(true); 22 | return response; 23 | } 24 | 25 | const int getHeader() const { 26 | return Outgoing::AvailabilityMessageComposer; 27 | } 28 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/login/HomeRoomMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/outgoing/MessageComposer.h" 11 | 12 | class HomeRoomMessageComposer : public MessageComposer { 13 | 14 | public: 15 | HomeRoomMessageComposer(int room_id, bool force_enter) : 16 | room_id(room_id), 17 | force_enter(force_enter) { } 18 | 19 | const Response compose() const { 20 | Response response = this->createResponse(); 21 | response.writeInt(room_id); 22 | response.writeInt(force_enter); 23 | return response; 24 | } 25 | 26 | const int getHeader() const { 27 | return Outgoing::HomeRoomMessageComposer; 28 | } 29 | private: 30 | int room_id; 31 | bool force_enter; 32 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/login/LandingWidgetMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/outgoing/MessageComposer.h" 11 | 12 | class LandingWidgetMessageComposer : public MessageComposer { 13 | 14 | public: 15 | LandingWidgetMessageComposer() { } 16 | 17 | const Response compose() const { 18 | Response response = this->createResponse(); 19 | response.writeInt(0); 20 | return response; 21 | } 22 | 23 | const int getHeader() const { 24 | return Outgoing::LandingWidgetMessageComposer; 25 | } 26 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/login/UniqueMachineIDMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/outgoing/MessageComposer.h" 11 | 12 | class UniqueMachineIDMessageComposer : public MessageComposer { 13 | 14 | public: 15 | UniqueMachineIDMessageComposer(std::string machine_id) : 16 | machine_id(machine_id) { } 17 | 18 | const Response compose() const { 19 | Response response = this->createResponse(); 20 | response.writeString(machine_id); 21 | return response; 22 | } 23 | 24 | const int getHeader() const { 25 | return Outgoing::UniqueMachineIDMessageComposer; 26 | } 27 | 28 | private: 29 | std::string machine_id; 30 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/messenger/FollowErrorMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/outgoing/MessageComposer.h" 11 | 12 | class FollowErrorMessageComposer : public MessageComposer { 13 | 14 | public: 15 | FollowErrorMessageComposer(int error_id) : 16 | error_id(error_id) { } 17 | 18 | const Response compose() const { 19 | Response response = this->createResponse(); 20 | response.writeInt(this->error_id); 21 | return response; 22 | } 23 | 24 | const int getHeader() const { 25 | return Outgoing::FollowErrorMessageComposer; 26 | } 27 | 28 | private: 29 | int error_id; 30 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/messenger/FollowFriendMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/outgoing/MessageComposer.h" 11 | 12 | class FollowFriendMessageComposer : public MessageComposer { 13 | 14 | public: 15 | FollowFriendMessageComposer(int room_id) : 16 | room_id(room_id) { } 17 | 18 | const Response compose() const { 19 | Response response = this->createResponse(); 20 | response.writeInt(this->room_id); 21 | return response; 22 | } 23 | 24 | const int getHeader() const { 25 | return Outgoing::FollowBuddyMessageComposer; 26 | } 27 | 28 | private: 29 | int room_id; 30 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/messenger/FriendsListMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | #include 12 | 13 | #include "game/messenger/MessengerUser.h" 14 | #include "communication/outgoing/MessageComposer.h" 15 | 16 | class FriendsListMessageComposer : public MessageComposer { 17 | 18 | public: 19 | FriendsListMessageComposer(const std::map friends) : 20 | friends(friends) { } 21 | 22 | const Response compose() const { 23 | Response response = this->createResponse(); 24 | response.writeInt(1); 25 | response.writeInt(0); 26 | response.writeInt(this->friends.size()); 27 | 28 | for (auto buddy : this->friends) { 29 | buddy.second->serialise(response, false, false); 30 | } 31 | 32 | return response; 33 | } 34 | 35 | const int getHeader() const { 36 | return Outgoing::InitMessengerMessageComposer; 37 | } 38 | 39 | private: 40 | const std::map friends; 41 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/messenger/MessageInviteMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/outgoing/MessageComposer.h" 11 | 12 | class MessageInviteMessageComposer : public MessageComposer { 13 | 14 | public: 15 | MessageInviteMessageComposer(int user_id, std::string message) : 16 | user_id(user_id), 17 | message(message) { } 18 | 19 | const Response compose() const { 20 | Response response = this->createResponse(); 21 | response.writeInt(this->user_id); 22 | response.writeString(this->message); 23 | return response; 24 | } 25 | 26 | const int getHeader() const { 27 | return Outgoing::MessageInviteMessageComposer; 28 | } 29 | 30 | public: 31 | int user_id; 32 | std::string message; 33 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/messenger/MessengerCategoriesMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | 12 | #include "communication/outgoing/MessageComposer.h" 13 | 14 | class MessengerCategoriesMessageComposer : public MessageComposer { 15 | 16 | public: 17 | MessengerCategoriesMessageComposer() { } 18 | 19 | /*public static final int MAX_FRIENDS_DEFAULT = 300; 20 | public static final int MAX_FRIENDS_BASIC = 800; 21 | public static final int MAX_FRIENDS_VIP = 1000;*/ 22 | 23 | const Response compose() const { 24 | Response response = this->createResponse(); 25 | response.writeInt(300); 26 | response.writeInt(800); 27 | response.writeInt(1000); 28 | response.writeInt(0); 29 | return response; 30 | } 31 | 32 | const int getHeader() const { 33 | return Outgoing::MessengerCategoriesMessageComposer; 34 | } 35 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/messenger/MessengerMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/outgoing/MessageComposer.h" 11 | 12 | class MessengerMessageComposer : public MessageComposer { 13 | 14 | public: 15 | MessengerMessageComposer(int from_id, std::string message) : 16 | from_id(from_id), 17 | message(message) { } 18 | 19 | const Response compose() const { 20 | Response response = this->createResponse(); 21 | response.writeInt(from_id); 22 | response.writeString(message); 23 | response.writeInt(0); 24 | return response; 25 | } 26 | 27 | const int getHeader() const { 28 | return Outgoing::MessengerMessageComposer; 29 | } 30 | 31 | private: 32 | int from_id; 33 | std::string message; 34 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/messenger/MessengerRequestsMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | 12 | #include "game/player/Player.h" 13 | #include "game/messenger/MessengerUser.h" 14 | #include "communication/outgoing/MessageComposer.h" 15 | 16 | class MessengerRequestsMessageComposer : public MessageComposer { 17 | 18 | public: 19 | MessengerRequestsMessageComposer(EntityDetails *details, std::map requests) : 20 | details(details), 21 | requests(requests) { } 22 | 23 | const Response compose() const { 24 | Response response = this->createResponse(); 25 | response.writeInt(this->details->id); 26 | response.writeInt(this->requests.size()); 27 | 28 | for (auto kvp : requests) { 29 | response.writeInt(kvp.second->getDetails()->id); 30 | response.writeString(kvp.second->getDetails()->username); 31 | response.writeString(kvp.second->getDetails()->figure); 32 | } 33 | 34 | return response; 35 | } 36 | 37 | const int getHeader() const { 38 | return Outgoing::MessengerRequestsMessageComposer; 39 | } 40 | 41 | private: 42 | EntityDetails *details; 43 | std::map requests; 44 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/messenger/MessengerSearchMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | 12 | #include "game/player/Player.h" 13 | #include "game/messenger/MessengerUser.h" 14 | #include "communication/outgoing/MessageComposer.h" 15 | 16 | class MessengerSearchMessageComposer : public MessageComposer { 17 | 18 | public: 19 | MessengerSearchMessageComposer(Player *player, std::vector search) : 20 | player(player), 21 | search(search) { } 22 | 23 | const Response compose() const { 24 | Response response = this->createResponse(); 25 | 26 | std::vector friends; 27 | std::vector strangers; 28 | 29 | for (int id : search) { 30 | if (id != player->getDetails()->id) { 31 | if (player->getMessenger()->isFriend(id)) { 32 | friends.push_back(MessengerUser(id)); 33 | } 34 | else { 35 | strangers.push_back(MessengerUser(id)); 36 | } 37 | } 38 | } 39 | 40 | response.writeInt(friends.size()); 41 | 42 | for (MessengerUser buddy : friends) { 43 | buddy.serialiseSearch(response); 44 | } 45 | 46 | response.writeInt(strangers.size()); 47 | for (MessengerUser stranger : strangers) { 48 | stranger.serialiseSearch(response); 49 | } 50 | 51 | return response; 52 | } 53 | 54 | const int getHeader() const { 55 | return Outgoing::MessengerSearchMessageComposer; 56 | } 57 | 58 | private: 59 | Player *player; 60 | std::vector search; 61 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/messenger/MessengerSendRequestComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | 12 | #include "communication/outgoing/MessageComposer.h" 13 | 14 | class MessengerSendRequestComposer : public MessageComposer { 15 | 16 | public: 17 | MessengerSendRequestComposer(EntityDetails *details) : 18 | details(details) { } 19 | 20 | const Response compose() const { 21 | Response response = this->createResponse(); 22 | response.writeInt(this->details->id); 23 | response.writeString(this->details->username); 24 | response.writeString(this->details->figure); 25 | return response; 26 | } 27 | 28 | const int getHeader() const { 29 | return Outgoing::MessengerSendRequest; 30 | } 31 | 32 | private: 33 | EntityDetails *details; 34 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/messenger/MessengerUpdateMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | 12 | #include "game/messenger/MessengerUser.h" 13 | #include "communication/outgoing/MessageComposer.h" 14 | 15 | class MessengerUpdateMessageComposer : public MessageComposer { 16 | 17 | public: 18 | MessengerUpdateMessageComposer(MessengerUser *messenger_user, const bool force_offline) : 19 | messenger_user(messenger_user), 20 | force_offline(force_offline) { } 21 | 22 | const Response compose() const { 23 | Response response = this->createResponse(); 24 | response.writeInt(0); 25 | response.writeInt(1); 26 | response.writeInt(0); 27 | messenger_user->serialise(response, force_offline); 28 | response.writeInt(0); 29 | return response; 30 | } 31 | 32 | const int getHeader() const { 33 | return Outgoing::FriendUpdateMessageComposer; 34 | } 35 | 36 | private: 37 | MessengerUser *messenger_user; 38 | bool force_offline; 39 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/messenger/RemoveFriendMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include "communication/outgoing/MessageComposer.h" 12 | 13 | class RemoveFriendMessageComposer : public MessageComposer { 14 | 15 | public: 16 | RemoveFriendMessageComposer(int user_id) : 17 | user_id(user_id) { } 18 | 19 | const Response compose() const { 20 | Response response = this->createResponse(); 21 | response.writeInt(0); 22 | response.writeInt(1); 23 | response.writeInt(-1); 24 | response.writeInt(user_id); 25 | return response; 26 | } 27 | 28 | const int getHeader() const { 29 | return Outgoing::RemoveFriendMessageComposer; 30 | } 31 | 32 | private: 33 | int user_id; 34 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/misc/BroadcastMessageAlertComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/outgoing/MessageComposer.h" 11 | 12 | class BroadcastMessageAlertComposer : public MessageComposer { 13 | 14 | public: 15 | BroadcastMessageAlertComposer(std::string message, std::string url = "") : 16 | message(message), 17 | url(url) { } 18 | 19 | const Response compose() const { 20 | Response response = this->createResponse(); 21 | response.writeString(message); 22 | response.writeString(url); 23 | return response; 24 | } 25 | 26 | const int getHeader() const { 27 | return Outgoing::BroadcastMessageAlertComposer; 28 | } 29 | 30 | private: 31 | std::string message; 32 | std::string url; 33 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/navigator/CanCreateRoomMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include "boot/Icarus.h" 12 | 13 | #include "communication/outgoing/MessageComposer.h" 14 | 15 | class CanCreateRoomMessageComposer : public MessageComposer { 16 | 17 | public: 18 | 19 | CanCreateRoomMessageComposer(Player *player) : 20 | player(player) { } 21 | 22 | const Response compose() const { 23 | 24 | Response response = this->createResponse(); 25 | response.writeInt(player->getRooms().size() >= Icarus::getGame()->MAX_ROOMS_PER_ACCOUNT ? 1 : 0); 26 | response.writeInt(Icarus::getGame()->MAX_ROOMS_PER_ACCOUNT); 27 | return response; 28 | } 29 | 30 | const int getHeader() const { 31 | return Outgoing::CanCreateRoomMessageComposer; 32 | } 33 | 34 | private: 35 | Player *player; 36 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/navigator/CreateRoomMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/outgoing/MessageComposer.h" 11 | 12 | class CreateRoomMessageComposer : public MessageComposer { 13 | 14 | public: 15 | CreateRoomMessageComposer(int room_id, std::string room_name) : 16 | room_id(room_id), 17 | room_name(room_name) { } 18 | 19 | const Response compose() const { 20 | Response response = this->createResponse(); 21 | response.writeInt(this->room_id); 22 | response.writeString(this->room_name); 23 | return response; 24 | } 25 | 26 | const int getHeader() const { 27 | return Outgoing::CreateRoomMessageComposer; 28 | } 29 | 30 | private: 31 | int room_id; 32 | std::string room_name; 33 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/navigator/FlatCategoriesMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | 12 | #include "game/navigator/NavigatorCategory.h" 13 | #include "communication/outgoing/MessageComposer.h" 14 | 15 | class FlatCategoriesMessageComposer : public MessageComposer { 16 | 17 | public: 18 | FlatCategoriesMessageComposer(std::vector categories, int rank) : 19 | categories(categories), 20 | rank(rank) { } 21 | 22 | const Response compose() const { 23 | Response response = this->createResponse(); 24 | response.writeInt(this->categories.size()); 25 | 26 | for (auto category : this->categories) { 27 | response.writeInt(category->id); 28 | response.writeString(category->name); 29 | response.writeBool(category->minimum_rank <= rank); 30 | response.writeBool(false); 31 | response.writeString("NONE"); 32 | response.writeString(""); 33 | response.writeBool(false); 34 | } 35 | 36 | return response; 37 | } 38 | 39 | const int getHeader() const { 40 | return Outgoing::FlatCategoriesMessageComposer; 41 | } 42 | 43 | private: 44 | std::vector categories; 45 | int rank; 46 | 47 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/navigator/NavigatorCategoriesComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | 12 | #include "game/navigator/NavigatorCategory.h" 13 | #include "communication/outgoing/MessageComposer.h" 14 | 15 | class NavigatorCategoriesComposer : public MessageComposer { 16 | 17 | public: 18 | NavigatorCategoriesComposer(std::vector categories) : 19 | categories(categories) { } 20 | 21 | const Response compose() const { 22 | Response response = this->createResponse(); 23 | response.writeInt(4 + ((int)categories.size())); 24 | 25 | for (auto category : categories) { 26 | response.writeString("category__" + category->name); 27 | } 28 | 29 | response.writeString("recommended"); 30 | response.writeString("new_ads"); 31 | response.writeString("staffpicks"); 32 | response.writeString("official"); 33 | return response; 34 | } 35 | 36 | const int getHeader() const { 37 | return Outgoing::NavigatorCategories; 38 | } 39 | 40 | private: 41 | std::vector categories; 42 | 43 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/navigator/NavigatorMetaDataComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "boot/Icarus.h" 11 | #include "communication/outgoing/MessageComposer.h" 12 | 13 | class NavigatorMetaDataComposer : public MessageComposer { 14 | 15 | public: 16 | NavigatorMetaDataComposer() { } 17 | 18 | const Response compose() const { 19 | 20 | auto parentTabs = Icarus::getGame()->getNavigatorManager()->getParentTabs(); 21 | Response response = this->createResponse(); 22 | response.writeInt((int)parentTabs.size()); 23 | 24 | for (auto tab : parentTabs) { 25 | response.writeString(tab->getTabName()); 26 | response.writeInt(0); 27 | } 28 | return response; 29 | } 30 | 31 | const int getHeader() const { 32 | return Outgoing::NavigatorMetaDataComposer; 33 | } 34 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/navigator/NavigatorPreferencesMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/outgoing/MessageComposer.h" 11 | 12 | class NavigatorPreferencesMessageComposer : public MessageComposer { 13 | 14 | public: 15 | NavigatorPreferencesMessageComposer() { } 16 | 17 | const Response compose() const { 18 | Response response = this->createResponse(); 19 | response.writeInt(68); 20 | response.writeInt(42); 21 | response.writeInt(425); 22 | response.writeInt(535); 23 | response.writeBool(false); 24 | response.writeInt(0); 25 | return response; 26 | } 27 | 28 | const int getHeader() const { 29 | return Outgoing::NavigatorPreferencesMessageComposer; 30 | } 31 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/room/RoomDataMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include "game/room/Room.h" 12 | #include "game/player/Player.h" 13 | 14 | #include "communication/outgoing/MessageComposer.h" 15 | 16 | class RoomDataMessageComposer : public MessageComposer { 17 | 18 | public: 19 | RoomDataMessageComposer(Room *room, Player *player, bool is_loading, bool check_entry) { 20 | this->room = room; 21 | this->player = player; 22 | this->is_loading = is_loading; 23 | this->check_entry = check_entry; 24 | } 25 | 26 | const Response compose() const { 27 | Response response = this->createResponse(); 28 | response.writeBool(this->is_loading); 29 | room->serialise(response, true); 30 | response.writeBool(this->check_entry); 31 | response.writeBool(false); 32 | response.writeBool(false); 33 | response.writeBool(false); 34 | response.writeInt(room->getData()->who_can_mute); 35 | response.writeInt(room->getData()->who_can_kick); 36 | response.writeInt(room->getData()->who_can_ban); 37 | response.writeBool(room->hasRights(player, true)); // TODO: Rights, true if moderator or room owner 38 | response.writeInt(room->getData()->chat_mode); 39 | response.writeInt(room->getData()->chat_size); 40 | response.writeInt(room->getData()->chat_speed); 41 | response.writeInt(room->getData()->chat_flood); 42 | response.writeInt(room->getData()->chat_distance); 43 | return response; 44 | } 45 | 46 | const int getHeader() const { 47 | return Outgoing::RoomDataMessageComposer; 48 | } 49 | 50 | private: 51 | Room *room; 52 | Player *player; 53 | bool is_loading; 54 | bool check_entry; 55 | 56 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/room/doorbell/AcceptUserInsideRoomMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/outgoing/MessageComposer.h" 11 | 12 | class AcceptUserInsideRoomMessageComposer : public MessageComposer { 13 | 14 | public: 15 | AcceptUserInsideRoomMessageComposer() { } 16 | 17 | const Response compose() const { 18 | Response response = this->createResponse(); 19 | response.writeInt(1); 20 | return response; 21 | } 22 | 23 | const int getHeader() const { 24 | return Outgoing::AcceptUserInsideRoomMessageComposer; 25 | } 26 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/room/doorbell/GenericDoorbellMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/outgoing/MessageComposer.h" 11 | 12 | class GenericDoorbellMessageComposer : public MessageComposer { 13 | 14 | public: 15 | GenericDoorbellMessageComposer(int notify_code) : 16 | notify_code(notify_code) { } 17 | 18 | GenericDoorbellMessageComposer(std::string username) : 19 | username(username) { } 20 | 21 | const Response compose() const { 22 | Response response = this->createResponse(); 23 | 24 | if (this->notify_code != -9001) { 25 | response.writeInt(this->notify_code); 26 | } 27 | else { 28 | response.writeString(this->username); 29 | } 30 | 31 | return response; 32 | } 33 | 34 | const int getHeader() const { 35 | return Outgoing::GenericDoorbellMessageComposer; 36 | } 37 | 38 | private: 39 | int notify_code = -9001; 40 | std::string username; 41 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/room/doorbell/GenericErrorMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/outgoing/MessageComposer.h" 11 | 12 | class GenericErrorMessageComposer : public MessageComposer { 13 | 14 | public: 15 | GenericErrorMessageComposer(int error_code) : 16 | error_code(error_code) { } 17 | 18 | const Response compose() const { 19 | Response response = this->createResponse(); 20 | response.writeInt(this->error_code); 21 | return response; 22 | } 23 | 24 | const int getHeader() const { 25 | return Outgoing::GenericErrorMessageComposer; 26 | } 27 | 28 | private: 29 | int error_code; 30 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/room/doorbell/GenericNoAnswerDoorbellMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/outgoing/MessageComposer.h" 11 | 12 | class GenericNoAnswerDoorbellMessageComposer : public MessageComposer { 13 | 14 | public: 15 | GenericNoAnswerDoorbellMessageComposer() {} 16 | 17 | const Response compose() const { 18 | Response response = this->createResponse(); 19 | response.writeString(""); 20 | return response; 21 | } 22 | 23 | const int getHeader() const { 24 | return Outgoing::GenericNoAnswerDoorbellMessageComposer; 25 | } 26 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/room/doorbell/RoomEnterErrorMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/outgoing/MessageComposer.h" 11 | 12 | class RoomEnterErrorMessageComposer : public MessageComposer { 13 | 14 | public: 15 | RoomEnterErrorMessageComposer(int error_code) : 16 | error_code(error_code) { } 17 | 18 | const Response compose() const { 19 | Response response = this->createResponse(); 20 | response.writeInt(this->error_code); 21 | return response; 22 | } 23 | 24 | const int getHeader() const { 25 | return Outgoing::RoomEnterErrorMessageComposer; 26 | } 27 | 28 | private: 29 | int error_code; 30 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/room/entry/HasOwnerRightsMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include "game/room/Room.h" 12 | #include "game/player/Player.h" 13 | 14 | #include "communication/outgoing/MessageComposer.h" 15 | 16 | class HasOwnerRightsMessageComposer : public MessageComposer { 17 | 18 | public: 19 | HasOwnerRightsMessageComposer() { } 20 | 21 | const Response compose() const { 22 | Response response = this->createResponse(); 23 | return response; 24 | } 25 | 26 | const int getHeader() const { 27 | return Outgoing::HasOwnerRightsMessageComposer; 28 | } 29 | 30 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/room/entry/NoRightsMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include "game/room/Room.h" 12 | #include "game/player/Player.h" 13 | 14 | #include "communication/outgoing/MessageComposer.h" 15 | 16 | class NoRightsMessageComposer : public MessageComposer { 17 | 18 | public: 19 | NoRightsMessageComposer() { } 20 | 21 | const Response compose() const { 22 | Response response = this->createResponse(); 23 | return response; 24 | } 25 | 26 | const int getHeader() const { 27 | return Outgoing::YouAreNotControllerMessageComposer; 28 | } 29 | 30 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/room/entry/PrepareRoomMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include "game/room/Room.h" 12 | #include "game/player/Player.h" 13 | 14 | #include "communication/outgoing/MessageComposer.h" 15 | 16 | class PrepareRoomMessageComposer : public MessageComposer { 17 | 18 | public: 19 | PrepareRoomMessageComposer(int room_id) : 20 | room_id(room_id) { } 21 | 22 | const Response compose() const { 23 | Response response = this->createResponse(); 24 | response.writeInt(this->room_id); 25 | return response; 26 | } 27 | 28 | const int getHeader() const { 29 | return Outgoing::RoomUpdateMessageComposer; 30 | } 31 | 32 | private: 33 | int room_id; 34 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/room/entry/RightsLevelMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include "game/room/Room.h" 12 | #include "game/player/Player.h" 13 | 14 | #include "communication/outgoing/MessageComposer.h" 15 | 16 | class RightsLevelMessageComposer : public MessageComposer { 17 | 18 | public: 19 | RightsLevelMessageComposer(int rights_level) : 20 | rights_level(rights_level) { } 21 | 22 | const Response compose() const { 23 | Response response = this->createResponse(); 24 | response.writeInt(rights_level); 25 | return response; 26 | } 27 | 28 | const int getHeader() const { 29 | return Outgoing::RightsLevelMessageComposer; 30 | } 31 | 32 | private: 33 | int rights_level; 34 | 35 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/room/entry/RoomModelMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include "game/room/Room.h" 12 | #include "game/player/Player.h" 13 | 14 | #include "communication/outgoing/MessageComposer.h" 15 | 16 | class RoomModelMessageComposer : public MessageComposer { 17 | 18 | public: 19 | RoomModelMessageComposer(std::string model_name, int room_id) : 20 | model_name(model_name), 21 | room_id(room_id) { } 22 | 23 | const Response compose() const { 24 | Response response = this->createResponse(); 25 | response.writeString(this->model_name); 26 | response.writeInt(this->room_id); 27 | return response; 28 | } 29 | 30 | const int getHeader() const { 31 | return Outgoing::InitialRoomInfoMessageComposer; 32 | } 33 | 34 | private: 35 | std::string model_name; 36 | int room_id; 37 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/room/entry/RoomOwnerRightsComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/outgoing/MessageComposer.h" 11 | 12 | class RoomOwnerRightsComposer : public MessageComposer { 13 | 14 | public: 15 | RoomOwnerRightsComposer(int user_id, bool has_rights) : 16 | user_id(user_id), 17 | has_rights(has_rights) { } 18 | 19 | const Response compose() const { 20 | Response response = this->createResponse(); 21 | response.writeInt(this->user_id); 22 | response.writeBool(this->has_rights); 23 | return response; 24 | } 25 | 26 | const int getHeader() const { 27 | return Outgoing::RoomOwnerRightsComposer; 28 | } 29 | 30 | private: 31 | int user_id; 32 | bool has_rights; 33 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/room/entry/RoomRatingMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include "game/room/Room.h" 12 | #include "game/player/Player.h" 13 | 14 | #include "communication/outgoing/MessageComposer.h" 15 | 16 | class RoomRatingMessageComposer : public MessageComposer { 17 | 18 | public: 19 | RoomRatingMessageComposer(int score) 20 | : score(score) { } 21 | 22 | const Response compose() const { 23 | Response response = this->createResponse(); 24 | response.writeInt(this->score); 25 | response.writeBool(false); 26 | return response; 27 | } 28 | 29 | const int getHeader() const { 30 | return Outgoing::RoomRatingMessageComposer; 31 | } 32 | 33 | private: 34 | int score; 35 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/room/entry/RoomSpacesMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include "game/room/Room.h" 12 | #include "game/player/Player.h" 13 | 14 | #include "communication/outgoing/MessageComposer.h" 15 | 16 | class RoomSpacesMessageComposer : public MessageComposer { 17 | 18 | public: 19 | RoomSpacesMessageComposer(std::string space, std::string data) : 20 | space(space), 21 | data(data) { } 22 | 23 | const Response compose() const { 24 | Response response = this->createResponse(); 25 | response.writeString(this->space); 26 | response.writeString(this->data); 27 | return response; 28 | } 29 | 30 | const int getHeader() const { 31 | return Outgoing::RoomSpacesMessageComposer; 32 | } 33 | 34 | private: 35 | std::string space; 36 | std::string data; 37 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/room/item/FloorItemsMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/outgoing/MessageComposer.h" 11 | #include "game/item/Item.h" 12 | 13 | class FloorItemsMessageComposer : public MessageComposer { 14 | 15 | public: 16 | FloorItemsMessageComposer(std::vector items) : 17 | items(items) { } 18 | 19 | const Response compose() const { 20 | Response response = this->createResponse(); 21 | response.writeInt(this->items.size()); 22 | 23 | for (Item *item : this->items) { 24 | response.writeInt(item->user_id); 25 | response.writeString(item->owner_name); 26 | } 27 | 28 | response.writeInt(this->items.size()); 29 | 30 | for (Item *item : this->items) { 31 | item->serialise(response); 32 | } 33 | 34 | return response; 35 | } 36 | 37 | const int getHeader() const { 38 | return Outgoing::FloorItemsMessageComposer; 39 | } 40 | 41 | private: 42 | std::vector items; 43 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/room/item/MoveItemMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/outgoing/MessageComposer.h" 11 | #include "game/item/Item.h" 12 | 13 | class MoveItemMessageComposer : public MessageComposer { 14 | 15 | public: 16 | MoveItemMessageComposer(Item *item) : 17 | item(item) { } 18 | 19 | const Response compose() const { 20 | Response response = this->createResponse(); 21 | item->serialise(response); 22 | return response; 23 | } 24 | 25 | const int getHeader() const { 26 | 27 | if (item->isWallItem()) { 28 | return Outgoing::MoveWallItemMessageComposer; 29 | } 30 | 31 | if (item->isFloorItem()) { 32 | return Outgoing::MoveFloorItemMessageComposer; 33 | } 34 | 35 | return -1; 36 | } 37 | 38 | private: 39 | Item *item; 40 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/room/item/PlaceItemMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/outgoing/MessageComposer.h" 11 | #include "game/item/Item.h" 12 | 13 | class PlaceItemMessageComposer : public MessageComposer { 14 | 15 | public: 16 | PlaceItemMessageComposer(Item *item) : 17 | item(item) { } 18 | 19 | const Response compose() const { 20 | Response response = this->createResponse(); 21 | item->serialise(response); 22 | response.writeString(item->owner_name); 23 | return response; 24 | } 25 | 26 | const int getHeader() const { 27 | 28 | if (item->isFloorItem()) { 29 | return Outgoing::PlaceFloorItemMessageComposer; 30 | } 31 | else { 32 | return Outgoing::PlaceWallItemMessageComposer; 33 | } 34 | } 35 | 36 | private: 37 | Item *item; 38 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/room/item/RemoveItemMessageComposer.h: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Icarus - A multi-platform C++ server 4 | * 5 | * Copyright 2016 Alex "Quackster" Miller 6 | * 7 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 8 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 9 | */ 10 | #pragma once 11 | #include "game/item/Item.h" 12 | #include "communication/outgoing/MessageComposer.h" 13 | 14 | class RemoveItemMessageComposer : public MessageComposer { 15 | 16 | public: 17 | RemoveItemMessageComposer(Item *item) : 18 | item(item) { } 19 | 20 | const Response compose() const { 21 | Response response = this->createResponse(); 22 | 23 | response.writeString(item->id); 24 | response.writeBool(false); 25 | response.writeInt(item->user_id); 26 | 27 | if (item->isFloorItem()) { 28 | response.writeInt(0); 29 | } 30 | 31 | return response; 32 | } 33 | 34 | const int getHeader() const { 35 | 36 | 37 | if (item->isFloorItem()) { 38 | return Outgoing::RemoveItemMessageComposer; 39 | } 40 | else { 41 | return Outgoing::RemoveWallItemMessageComposer;; 42 | } 43 | } 44 | 45 | private: 46 | Item *item; 47 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/room/item/WallItemsMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/outgoing/MessageComposer.h" 11 | #include "game/item/Item.h" 12 | 13 | class WallItemsMessageComposer : public MessageComposer { 14 | 15 | public: 16 | WallItemsMessageComposer(std::vector items) : 17 | items(items) { } 18 | 19 | const Response compose() const { 20 | Response response = this->createResponse(); 21 | response.writeInt(this->items.size()); 22 | 23 | for (Item *item : this->items) { 24 | response.writeInt(item->user_id); 25 | response.writeString(item->owner_name); 26 | } 27 | 28 | response.writeInt(this->items.size()); 29 | 30 | for (Item *item : this->items) { 31 | item->serialise(response); 32 | } 33 | 34 | return response; 35 | } 36 | 37 | const int getHeader() const { 38 | return Outgoing::WallItemsMessageComposer; 39 | } 40 | 41 | private: 42 | std::vector items; 43 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/room/model/FloorMapMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include "boot/Icarus.h" 12 | #include "game/room/model/RoomModel.h" 13 | 14 | #include "game/room/Room.h" 15 | #include "game/player/Player.h" 16 | 17 | #include "communication/outgoing/MessageComposer.h" 18 | 19 | class FloorMapMessageComposer : public MessageComposer { 20 | 21 | public: 22 | FloorMapMessageComposer(Room *room) : 23 | room(room) { } 24 | 25 | const Response compose() const { 26 | 27 | RoomModel *model = room->getModel(); 28 | 29 | Response response = this->createResponse(); 30 | response.writeBool(true); 31 | response.writeInt(room->getData()->wall_height); 32 | response.writeString(model->floor_map); 33 | 34 | return response; 35 | } 36 | 37 | const int getHeader() const { 38 | return Outgoing::FloorMapMessageComposer; 39 | } 40 | 41 | private: 42 | Room *room; 43 | 44 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/room/model/HeightMapMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include "boot/Icarus.h" 12 | #include "game/room/model/RoomModel.h" 13 | 14 | #include "game/room/Room.h" 15 | #include "game/player/Player.h" 16 | 17 | #include "communication/outgoing/MessageComposer.h" 18 | 19 | class HeightMapMessageComposer : public MessageComposer { 20 | 21 | public: 22 | HeightMapMessageComposer(Room *room) : 23 | room(room) { } 24 | 25 | const Response compose() const { 26 | 27 | RoomModel *model = room->getModel(); 28 | 29 | Response response = this->createResponse(); 30 | 31 | response.writeInt(model->map_size_x); 32 | response.writeInt(model->map_size_x * model->map_size_x); 33 | 34 | for (int y = 0; y < model->map_size_y; y++) { 35 | for (int x = 0; x < model->map_size_x; x++) { 36 | response.writeShort(model->getSquareHeight(x, y) * 256); 37 | } 38 | } 39 | 40 | return response; 41 | } 42 | 43 | const int getHeader() const { 44 | return Outgoing::HeightMapMessageComposer; 45 | } 46 | 47 | private: 48 | Room *room; 49 | 50 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/room/user/DanceStatusMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/outgoing/MessageComposer.h" 11 | 12 | class DanceStatusMessageComposer : public MessageComposer { 13 | 14 | public: 15 | DanceStatusMessageComposer(int virtual_id, int dance_id) : 16 | virtual_id(virtual_id), 17 | dance_id(dance_id) { } 18 | 19 | const Response compose() const { 20 | Response response = this->createResponse(); 21 | response.writeInt(this->virtual_id); 22 | response.writeInt(this->dance_id); 23 | return response; 24 | } 25 | 26 | const int getHeader() const { 27 | return Outgoing::DanceStatusMessageComposer; 28 | } 29 | 30 | private: 31 | int virtual_id; 32 | int dance_id; 33 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/room/user/FloodFilterMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/outgoing/MessageComposer.h" 11 | 12 | class FloodFilterMessageComposer : public MessageComposer { 13 | 14 | public: 15 | FloodFilterMessageComposer(int seconds) : 16 | seconds(seconds) { } 17 | 18 | const Response compose() const { 19 | Response response = this->createResponse(); 20 | response.writeInt(this->seconds); 21 | return response; 22 | } 23 | 24 | const int getHeader() const { 25 | return Outgoing::FloodFilterMessageComposer; 26 | } 27 | 28 | private: 29 | int seconds; 30 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/room/user/IdleStatusMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/outgoing/MessageComposer.h" 11 | 12 | class IdleStatusMessageComposer : public MessageComposer { 13 | 14 | public: 15 | IdleStatusMessageComposer(int virtual_id, bool asleep) : 16 | virtual_id(virtual_id), 17 | asleep(asleep) { } 18 | 19 | const Response compose() const { 20 | Response response = this->createResponse(); 21 | response.writeInt(this->virtual_id); 22 | response.writeBool(this->asleep); 23 | return response; 24 | } 25 | 26 | const int getHeader() const { 27 | return Outgoing::IdleStatusMessageComposer; 28 | } 29 | 30 | private: 31 | int virtual_id; 32 | bool asleep; 33 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/room/user/RemoveUserMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | 12 | #include "communication/outgoing/MessageComposer.h" 13 | 14 | class RemoveUserMessageComposer : public MessageComposer { 15 | 16 | public: 17 | RemoveUserMessageComposer(int virtual_id) : 18 | virtual_id(virtual_id) { } 19 | 20 | const Response compose() const { 21 | Response response = this->createResponse(); 22 | response.writeString(std::to_string(this->virtual_id)); 23 | return response; 24 | } 25 | 26 | const int getHeader() const { 27 | return Outgoing::RemoveUserMessageComposer; 28 | } 29 | 30 | private: 31 | int virtual_id; 32 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/room/user/TalkMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/outgoing/MessageComposer.h" 11 | 12 | class TalkMessageComposer : public MessageComposer { 13 | 14 | public: 15 | TalkMessageComposer(int virtual_id, bool shout, std::string message, int count, int text_colour) : 16 | virtual_id(virtual_id), 17 | shout(shout), 18 | message(message), 19 | count(count), 20 | text_colour(text_colour) { } 21 | 22 | const Response compose() const { 23 | Response response = this->createResponse(); 24 | response.writeInt(this->virtual_id); 25 | response.writeString(this->message); 26 | response.writeInt(0); 27 | response.writeInt(this->text_colour); 28 | response.writeInt(0); 29 | response.writeInt(this->count); 30 | return response; 31 | } 32 | 33 | const int getHeader() const { 34 | return shout ? Outgoing::ShoutMessageComposer : Outgoing::ChatMessageComposer; 35 | } 36 | 37 | private: 38 | int virtual_id; 39 | bool shout; 40 | std::string message; 41 | int count; 42 | int text_colour; 43 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/room/user/TypingStatusMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/outgoing/MessageComposer.h" 11 | 12 | class TypingStatusMessageComposer : public MessageComposer { 13 | 14 | public: 15 | TypingStatusMessageComposer(int virtual_id, bool is_typing) : 16 | virtual_id(virtual_id), 17 | is_typing(is_typing) { } 18 | 19 | const Response compose() const { 20 | Response response = this->createResponse(); 21 | response.writeInt(this->virtual_id); 22 | response.writeInt(this->is_typing); 23 | return response; 24 | } 25 | 26 | const int getHeader() const { 27 | return Outgoing::TypingStatusMessageComposer; 28 | } 29 | 30 | private: 31 | int virtual_id; 32 | bool is_typing; 33 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/user/CreditsMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | 12 | #include "communication/outgoing/MessageComposer.h" 13 | 14 | class CreditsMessageComposer : public MessageComposer { 15 | 16 | public: 17 | CreditsMessageComposer(int credits) : 18 | credits(credits) { } 19 | 20 | const Response compose() const { 21 | Response response = this->createResponse(); 22 | response.writeString(std::to_string(credits)); 23 | return response; 24 | } 25 | 26 | const int getHeader() const { 27 | return Outgoing::CreditsMessageComposer; 28 | } 29 | 30 | private: 31 | int credits; 32 | 33 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/user/HotelViewMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | 12 | #include "communication/outgoing/MessageComposer.h" 13 | 14 | class HotelViewMessageComposer : public MessageComposer { 15 | 16 | public: 17 | HotelViewMessageComposer() { } 18 | 19 | const Response compose() const { 20 | Response response = this->createResponse();; 21 | return response; 22 | } 23 | 24 | const int getHeader() const { 25 | return Outgoing::HotelScreenMessageComposer; 26 | } 27 | 28 | 29 | }; -------------------------------------------------------------------------------- /src/communication/outgoing/user/UserObjectMessageComposer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | 12 | #include "game/player/Player.h" 13 | #include "communication/outgoing/MessageComposer.h" 14 | 15 | class UserObjectMessageComposer : public MessageComposer { 16 | 17 | public: 18 | UserObjectMessageComposer(Player *player) : 19 | player(player) { } 20 | 21 | const Response compose() const { 22 | Response response = this->createResponse(); 23 | response.writeInt(player->getDetails()->id); 24 | response.writeString(player->getDetails()->username); 25 | response.writeString(player->getDetails()->figure); 26 | response.writeString("M"); 27 | response.writeString(player->getDetails()->motto); 28 | response.writeString(""); 29 | response.writeBool(false); 30 | response.writeInt(0); // Respect 31 | response.writeInt(3); // Daily Respect Points 32 | response.writeInt(3); // Daily Pet Respect Points 33 | response.writeBool(true); 34 | response.writeString("1448526834"); 35 | response.writeBool(true); 36 | response.writeBool(false); 37 | return response; 38 | } 39 | 40 | const int getHeader() const { 41 | return Outgoing::UserObjectMessageComposer; 42 | } 43 | 44 | private: 45 | Player *player; 46 | 47 | }; -------------------------------------------------------------------------------- /src/communication/streams/Request.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #include "stdafx.h" 10 | #include "Request.h" 11 | 12 | /* 13 | Request constructor 14 | 15 | @return full received packet 16 | */ 17 | Request::Request(int length, char *full_message) : 18 | length(length), 19 | bytes(full_message), 20 | offset(0) { 21 | 22 | if (length > 0) { 23 | this->header = this->readShort(); 24 | } 25 | } 26 | 27 | Request::~Request() { } 28 | 29 | /* 30 | Read an boolean represented as 1 byte 31 | 32 | @return boolean 33 | */ 34 | bool Request::readBool() { 35 | 36 | char number = ((int)bytes[offset]) == 1; 37 | 38 | offset = offset + 1; 39 | return number; 40 | } 41 | 42 | /* 43 | Read an integer represented as 16 bits 44 | 45 | @return integer 46 | */ 47 | short Request::readShort() { 48 | 49 | short number = (short)( 50 | (0xff & bytes[offset]) << 8 | 51 | (0xff & bytes[offset + 1]) << 0); 52 | 53 | offset = offset + 2; 54 | return number; 55 | } 56 | 57 | 58 | /* 59 | Read an integer represented as 32 bits 60 | 61 | @return integer 62 | */ 63 | long Request::readInt() { 64 | 65 | long result = (int)bytes[offset + 3] & 0xff; 66 | result |= ((int)bytes[offset + 2] & 0xff) << 8; 67 | result |= ((int)bytes[offset + 1] & 0xff) << 16; 68 | result |= ((int)bytes[offset] & 0xff) << 24; 69 | 70 | offset = offset + 4; 71 | return result & 0xFFFFFFFFL; 72 | 73 | } 74 | 75 | /* 76 | Read a string with a 16bit length prefixed 77 | 78 | @return string 79 | */ 80 | std::string Request::readString() { 81 | std::string str; 82 | 83 | int length = readShort(); 84 | 85 | for (int i = 0; i < length; i++) { 86 | str += this->bytes[offset++]; 87 | } 88 | 89 | return str; 90 | } 91 | 92 | -------------------------------------------------------------------------------- /src/communication/streams/Request.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | class Request 12 | { 13 | 14 | public: 15 | Request(int length, char *full_message); 16 | ~Request(); 17 | 18 | short readShort(); 19 | long readInt(); 20 | bool readBool(); 21 | std::string readString(); 22 | 23 | int getMessageLength() { return length; } 24 | short getMessageId() { return header; } 25 | char* getBuffer() { return bytes; } 26 | 27 | private: 28 | short header; 29 | int length; 30 | int offset; 31 | 32 | char *bytes; 33 | }; -------------------------------------------------------------------------------- /src/communication/streams/Response.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include 12 | #include 13 | #include 14 | #include // Required for G++/GCC compilation with function "strlen" 15 | 16 | class Response 17 | { 18 | 19 | public: 20 | Response() : header(0) {}; 21 | Response(short header); 22 | ~Response(); 23 | void writeInt(int number); 24 | void writeInt(bool flag) { this->writeInt(flag ? 1 : 0); } 25 | void writeInt(size_t number) { this->writeInt((int)number); } 26 | void writeBool(bool flag) { 27 | this->message.push_back(flag ? (char)1 : (char)0); 28 | this->index = this->index + 1; 29 | } 30 | void writeShort(short numberr); 31 | void writeString(const char* str) { this->writeCChar(str); }; 32 | void writeString(int str) { this->writeString(std::to_string(str)); }; 33 | void writeString(std::string str) { this->writeCChar(str.c_str()); }; 34 | 35 | char *getData(); 36 | //char *getBytes(short num); 37 | //char *getBytes(int num, bool reverse = false); 38 | 39 | int getBytesWritten() { return index + 4/*the length at the start*/; } 40 | std::vector getMessage() { return message; } 41 | int getHeader() { return header; } 42 | 43 | private: 44 | short header; 45 | int index; 46 | bool used; 47 | std::vector message; 48 | void writeCChar(const char* str); 49 | enum { MAX_RESPONSE_SIZE = 1024 }; 50 | }; 51 | 52 | -------------------------------------------------------------------------------- /src/dao/CatalogueDao.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | class CatalogueTab; 16 | class CataloguePage; 17 | class CatalogueItem; 18 | class CatalogueDao 19 | { 20 | 21 | private: 22 | CatalogueDao() { }; 23 | 24 | public: 25 | static std::vector getTabs(int child_id); 26 | static std::map getPages(); 27 | static std::map getItems(); 28 | }; 29 | 30 | -------------------------------------------------------------------------------- /src/dao/ItemDao.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | #include 12 | #include 13 | 14 | #include "game/item/definitions/ItemDefinition.h" 15 | 16 | class Item; 17 | class ItemDao 18 | { 19 | 20 | private: 21 | ItemDao() { }; 22 | 23 | public: 24 | static std::map getItemDefinitions(); 25 | 26 | static std::vector getInventoryItems(int user_id); 27 | static std::vector getRoomItems(int room_id); 28 | 29 | static Item *newItem(int item_id, int owner_id, std::string extra_data); 30 | static void save(Item *item); 31 | static void remove(Item *item); 32 | }; 33 | 34 | -------------------------------------------------------------------------------- /src/dao/MessengerDao.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | #include 12 | 13 | #include "mysql_connection.h" 14 | #include "mysql.h" 15 | 16 | class MessengerUser; 17 | class MessengerDao 18 | { 19 | 20 | private: 21 | MessengerDao() { }; 22 | 23 | public: 24 | static std::map getFriends(int user_id); 25 | static std::map getRequests(int user_id); 26 | static std::vector search(std::string query); 27 | static bool newRequest(int fromId, int toId); 28 | static bool removeRequest(int fromId, int toId); 29 | static bool removeFriend(int fromId, int toId); 30 | static bool newFriend(int sender, int receiver); 31 | static void offlineMessage(int to, int from, std::string message, bool offline = false); 32 | static std::map getOfflineMessages(int user_id); 33 | static void readMessages(int user_id); 34 | 35 | }; 36 | 37 | -------------------------------------------------------------------------------- /src/dao/MySQLDao.cpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "stdafx.h" 3 | #include "dao/MySQLDao.h" 4 | #include "boot/Icarus.h" 5 | 6 | /* 7 | Returns true/false if a query has rows existing 8 | 9 | @param sql query 10 | @return bool 11 | */ 12 | 13 | bool MySQLDao::exists(std::string query) { 14 | 15 | bool output = false; 16 | std::shared_ptr connection = Icarus::getDatabaseManager()->getConnectionPool()->borrow(); 17 | 18 | try { 19 | std::shared_ptr sql_connection = connection->sql_connection; 20 | std::shared_ptr statement = std::shared_ptr(sql_connection->createStatement()); 21 | std::shared_ptr result_set = std::shared_ptr(statement->executeQuery(query)); 22 | output = result_set->next(); 23 | } 24 | catch (sql::SQLException &e) { 25 | Icarus::getDatabaseManager()->printException(e, __FILE__, __FUNCTION__, __LINE__); 26 | } 27 | 28 | Icarus::getDatabaseManager()->getConnectionPool()->unborrow(connection); 29 | 30 | return output; 31 | } 32 | 33 | bool MySQLDao::execute(std::string query) { 34 | 35 | bool output = false; 36 | std::shared_ptr connection = Icarus::getDatabaseManager()->getConnectionPool()->borrow(); 37 | 38 | try { 39 | std::shared_ptr sql_connection = connection->sql_connection; 40 | std::shared_ptr statement = std::shared_ptr(sql_connection->createStatement()); 41 | statement->execute(query); 42 | } 43 | catch (sql::SQLException &e) { 44 | Icarus::getDatabaseManager()->printException(e, __FILE__, __FUNCTION__, __LINE__); 45 | } 46 | 47 | Icarus::getDatabaseManager()->getConnectionPool()->unborrow(connection); 48 | 49 | return output; 50 | } 51 | -------------------------------------------------------------------------------- /src/dao/MySQLDao.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | #include 12 | 13 | #include "mysql_connection.h" 14 | #include "mysql.h" 15 | 16 | #include "game/player/Player.h" 17 | 18 | class MySQLDao 19 | { 20 | 21 | private: 22 | MySQLDao() { }; 23 | 24 | public: 25 | static bool exists(std::string query); 26 | static bool execute(std::string query); 27 | }; 28 | 29 | -------------------------------------------------------------------------------- /src/dao/NavigatorDao.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | #include 12 | 13 | #include "game/navigator/NavigatorTab.h" 14 | #include "game/navigator/NavigatorCategory.h" 15 | 16 | #include "mysql_connection.h" 17 | #include "mysql.h" 18 | 19 | class RoomData; 20 | class Room; 21 | 22 | enum NavigatorQuery { 23 | NAVIGATOR_FRIENDS_ROOMS 24 | }; 25 | 26 | class NavigatorDao 27 | { 28 | 29 | private: 30 | NavigatorDao() { }; 31 | 32 | public: 33 | static int createRoom(std::string room_name, std::string description, std::string room_model, int owner_id, int category, int max_users, int trade_settings); 34 | static std::vector getTabsByChildId(int child_id); 35 | static std::vector getCategories(); 36 | static std::vector getPreviewRooms(NavigatorQuery query, int user_id); 37 | }; 38 | 39 | -------------------------------------------------------------------------------- /src/dao/RoomDao.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | #include 12 | 13 | #include "game/room/Room.h" 14 | #include "game/room/RoomManager.h" 15 | #include "game/room/model/RoomModel.h" 16 | 17 | #include "mysql_connection.h" 18 | #include "mysql.h" 19 | 20 | class RoomNewbie; 21 | class RoomDao 22 | { 23 | 24 | private: 25 | RoomDao() { }; 26 | 27 | public: 28 | static std::map getModels(); 29 | static void resetRooms(); 30 | static std::vector RoomDao::getNewbieRoomSelection(); 31 | static std::vector getPlayerRooms(int user_id); 32 | static void addPublicRooms(); 33 | static Room* getRoom(int room_id); 34 | static std::vector getRooms(std::vector room_ids); 35 | static std::vector getRights(int room_id); 36 | static void deleteRoom(int room_id); 37 | static void updateRoom(int room_id, Room *room); 38 | }; 39 | 40 | -------------------------------------------------------------------------------- /src/dao/UserDao.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | #include 12 | 13 | #include "mysql_connection.h" 14 | #include "mysql.h" 15 | 16 | #include "game/player/Player.h" 17 | 18 | class UserDao 19 | { 20 | 21 | private: 22 | UserDao() { }; 23 | 24 | public: 25 | 26 | static bool exists(std::string sso_ticket); 27 | static std::string getName(int user_id); 28 | static int getIdByUsername(std::string username); 29 | static EntityDetails *findUserByTicket(Player *player, std::string sso_ticket); 30 | static std::shared_ptr getDetails(int user_id); 31 | static void updateUser(int user_id, EntityDetails *details); 32 | }; 33 | 34 | -------------------------------------------------------------------------------- /src/database/DatabaseManager.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | #include 12 | 13 | #include "mysql_connection.h" 14 | #include "database/lib/MySQLConnection.h" 15 | 16 | class DatabaseManager { 17 | 18 | public: 19 | DatabaseManager(std::string host, std::string port, std::string username, std::string password, std::string database, int pool_size); 20 | ~DatabaseManager(); 21 | bool testConnection(); 22 | void printException(sql::SQLException &e, char* file, char* function, int line); 23 | 24 | MySQLConnectionFactory *getConnectionFactory() { return this->mysql_connection_factory; } 25 | ConnectionPool *getConnectionPool() { return this->mysql_pool; } 26 | 27 | private: 28 | std::string host; 29 | std::string port; 30 | std::string username; 31 | std::string password; 32 | std::string database; 33 | bool tested_connection; 34 | int pool_size; 35 | 36 | MySQLConnectionFactory *mysql_connection_factory; 37 | ConnectionPool *mysql_pool; 38 | 39 | }; -------------------------------------------------------------------------------- /src/game/Game.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #include "stdafx.h" 10 | 11 | #include "Game.h" 12 | 13 | #include "boot/Icarus.h" 14 | #include "dao/RoomDao.h" 15 | 16 | Game::Game() { } 17 | 18 | /* 19 | Function that loads data after everything else needed to be loaded first 20 | 21 | @return none 22 | */ 23 | void Game::createGame() { 24 | 25 | // Load game order 26 | this->navigator_manager = new NavigatorManager(); 27 | this->executor_service = ExecutorService::createSchedulerService(Icarus::getGameConfiguration()->getInt("thread.pool.size"), std::chrono::milliseconds(500)); 28 | this->furniture_manager = new ItemManager(); 29 | this->catalogue_manager = new CatalogueManager(); 30 | this->room_manager = new RoomManager(); 31 | 32 | this->catalogue_manager->assignFurnitureData(); 33 | 34 | RoomDao::resetRooms(); 35 | RoomDao::addPublicRooms(); 36 | } 37 | 38 | Game::~Game() { 39 | 40 | // Stop executor service 41 | this->executor_service->stop(); 42 | 43 | // Delete pointers 44 | delete this->navigator_manager; 45 | delete this->room_manager; 46 | delete this->executor_service; 47 | } 48 | -------------------------------------------------------------------------------- /src/game/Game.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "game/navigator/NavigatorManager.h" 11 | #include "game/room/RoomManager.h" 12 | #include "game/catalogue/CatalogueManager.h" 13 | #include "game/item/ItemManager.h" 14 | 15 | #include "thread/ExecutorService.h" 16 | 17 | class Game 18 | { 19 | public: 20 | Game(); 21 | ~Game(); 22 | void createGame(); 23 | 24 | int MAX_ROOMS_PER_ACCOUNT = 20; 25 | 26 | NavigatorManager *getNavigatorManager() { return navigator_manager; } 27 | ExecutorService *getGameScheduler() { return executor_service; } 28 | RoomManager *getRoomManager() { return room_manager; } 29 | CatalogueManager *getCatalogueManager() { return catalogue_manager; } 30 | ItemManager *getItemManager() { return furniture_manager; } 31 | 32 | private: 33 | NavigatorManager *navigator_manager; 34 | ExecutorService *executor_service; 35 | RoomManager *room_manager; 36 | CatalogueManager *catalogue_manager; 37 | ItemManager *furniture_manager; 38 | }; 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /src/game/bot/Bot.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #include "stdafx.h" 10 | 11 | #include "game/bot/Bot.h" 12 | 13 | #include "boot/Icarus.h" 14 | 15 | /* 16 | Session constructor 17 | 18 | @param NetworkConnection ptr 19 | @return session instance 20 | */ 21 | Bot::Bot(EntityDetails *details) : 22 | details(details), 23 | room_user(new RoomUser(this)) { 24 | 25 | } 26 | 27 | 28 | Bot::~Bot() { 29 | delete details; 30 | delete room_user; 31 | } 32 | -------------------------------------------------------------------------------- /src/game/bot/Bot.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include "network/NetworkConnection.h" 12 | 13 | #include "game/entities/Entity.h" 14 | 15 | class Bot : public Entity { 16 | 17 | public: 18 | Bot(EntityDetails *details); 19 | ~Bot(); 20 | 21 | RoomUser *getRoomUser() { return room_user; } 22 | EntityDetails *getDetails() { return this->details; } 23 | 24 | void setDetails(EntityDetails *details) { this->details = details; }; 25 | void setRoomUser(RoomUser *room_user) { this->room_user = room_user; }; 26 | 27 | EntityType getEntityType() { EntityType type = BOT; return type; } 28 | 29 | 30 | 31 | private: 32 | EntityDetails *details = nullptr; 33 | RoomUser *room_user = nullptr; 34 | }; -------------------------------------------------------------------------------- /src/game/catalogue/CatalogueItem.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | #include "game/item/definitions/ItemDefinition.h" 12 | 13 | class Response; 14 | class CatalogueItem { 15 | 16 | public: 17 | CatalogueItem(); 18 | ~CatalogueItem(); 19 | void serialise(Response &response); 20 | ItemDefinition *getDefinition() { return this->item_definition; } 21 | void setDefinition(ItemDefinition *definition) { this->item_definition = definition; } 22 | 23 | int id = -1; 24 | int page_id = -1; 25 | int item_id; 26 | std::string catalogue_name; 27 | int cost_credits; 28 | int cost_pixels; 29 | int cost_snow; 30 | int amount; 31 | int vip; 32 | int achievement; 33 | int song_id; 34 | int limited_sells; 35 | int limited_stack; 36 | bool offer_active; 37 | std::string extra_data; 38 | std::string badge_id; 39 | int flat_id; 40 | 41 | private: 42 | ItemDefinition *item_definition = nullptr; 43 | 44 | }; -------------------------------------------------------------------------------- /src/game/catalogue/CatalogueManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | #include "CatalogueTab.h" 6 | #include "CataloguePage.h" 7 | #include "CatalogueItem.h" 8 | 9 | class CatalogueManager 10 | { 11 | public: 12 | CatalogueManager(); 13 | ~CatalogueManager(); 14 | 15 | void assignFurnitureData(); 16 | void loadCatalogueTabs(CatalogueTab *tab, int parent_id); 17 | 18 | std::vector getParentTabs(int rank); 19 | 20 | CataloguePage *getPage(int page_id); 21 | std::vector getItemsByPage(int page_id) { return this->getPage(page_id)->items; } 22 | CatalogueItem *getItem(int item_id); 23 | 24 | std::map getPages() { return pages; } 25 | std::map getItems() { return items; } 26 | 27 | private: 28 | std::vector parent_tabs; 29 | std::map items; 30 | std::map pages; 31 | }; 32 | 33 | -------------------------------------------------------------------------------- /src/game/catalogue/CataloguePage.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include "game/catalogue/CatalogueItem.h" 12 | 13 | #include 14 | 15 | struct CataloguePage { 16 | int id = -1; 17 | std::string caption; 18 | int parent_id = -1; 19 | std::string type; 20 | std::string layout; 21 | int minimum_rank; 22 | 23 | std::vector images; 24 | std::vector texts; 25 | std::vector items; 26 | }; -------------------------------------------------------------------------------- /src/game/catalogue/CatalogueTab.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | 12 | struct CatalogueTab 13 | { 14 | int id; 15 | int parent_id; 16 | std::string caption; 17 | int icon_colour; 18 | int icon_image; 19 | bool enabled; 20 | int min_rank; 21 | std::vector *child_tabs = new std::vector(); 22 | }; 23 | 24 | -------------------------------------------------------------------------------- /src/game/entities/Entity.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | #include "game/room/RoomUser.h" 12 | 13 | #include "game/entities/EntityDetails.h" 14 | #include "game/entities/EntityType.h" 15 | 16 | class Entity 17 | { 18 | 19 | public: 20 | virtual ~Entity() { } 21 | 22 | virtual EntityDetails *getDetails() = 0; 23 | virtual void setDetails(EntityDetails *details) = 0; 24 | 25 | virtual RoomUser *getRoomUser() = 0; 26 | virtual void setRoomUser(RoomUser *room_user) = 0; 27 | 28 | virtual EntityType getEntityType() = 0; 29 | 30 | }; 31 | -------------------------------------------------------------------------------- /src/game/entities/EntityDetails.cpp: -------------------------------------------------------------------------------- 1 | #include "Entity.h" 2 | #include "game/player/Player.h" 3 | #include "EntityDetails.h" 4 | 5 | #include "communication/outgoing/user/CreditsMessageComposer.h" 6 | 7 | EntityDetails::EntityDetails(Entity *entity) : 8 | entity(entity) { } 9 | 10 | EntityDetails::~EntityDetails() { 11 | 12 | 13 | } 14 | 15 | void EntityDetails::setCredits(int new_amount) { 16 | 17 | this->credits = new_amount; 18 | 19 | if (entity->getEntityType() == PLAYER) { 20 | Player *player = dynamic_cast(entity); 21 | player->send(CreditsMessageComposer(new_amount)); 22 | } 23 | } -------------------------------------------------------------------------------- /src/game/entities/EntityDetails.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | class Entity; 12 | class EntityDetails 13 | { 14 | 15 | public: 16 | EntityDetails(Entity *entity); 17 | ~EntityDetails(); 18 | 19 | void setCredits(int new_amount); 20 | 21 | Entity *entity; 22 | 23 | int id; 24 | std::string username; 25 | std::string motto; 26 | std::string figure; 27 | int rank; 28 | int credits; 29 | std::string machine_id; 30 | bool authenticated; 31 | bool has_logged_in = true; 32 | }; -------------------------------------------------------------------------------- /src/game/entities/EntityType.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | enum EntityType { 11 | PLAYER, 12 | BOT 13 | }; -------------------------------------------------------------------------------- /src/game/item/Item.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | #include "game/pathfinder/Position.h" 12 | 13 | class BaseInteractor; 14 | class ItemDefinition; 15 | class Response; 16 | class Room; 17 | class Item 18 | { 19 | public: 20 | Item(int id, int user_id, int owner_id, int item_id, int room_id, std::string x, std::string y, double z, int rotation, std::string extra_data); 21 | ~Item(); 22 | 23 | std::string getWallPosition(); 24 | void parseWallPosition(std::string position); 25 | 26 | void updateEntities(); 27 | void updateStatus(); 28 | 29 | bool hasEntityCollision(int x, int y); 30 | void save(); 31 | 32 | void remove(); 33 | 34 | bool isWallItem(); 35 | bool isFloorItem(); 36 | 37 | std::map getAffectedTiles(); 38 | bool canWalk(); 39 | void serialise(Response &response); 40 | 41 | ItemDefinition *getDefinition() { return this->item_definition; } 42 | Room *getRoom(); 43 | BaseInteractor *getInteractor(); 44 | 45 | 46 | 47 | int id = -1; 48 | int user_id = -1; 49 | int owner_id = -1; 50 | std::string owner_name = ""; 51 | int item_id = -1; 52 | int room_id = -1; 53 | int x = -1; 54 | int y = -1; 55 | double z = 0; 56 | int rotation = 0; 57 | std::string extra_data = ""; 58 | 59 | char side; 60 | int width_x; 61 | int width_y; 62 | int length_x; 63 | int length_y; 64 | 65 | private: 66 | ItemDefinition *item_definition = nullptr; 67 | }; 68 | 69 | -------------------------------------------------------------------------------- /src/game/item/ItemManager.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | 10 | #include "stdafx.h" 11 | 12 | #include "dao/ItemDao.h" 13 | 14 | #include "Item.h" 15 | #include "definitions/ItemDefinition.h" 16 | 17 | #include "ItemManager.h" 18 | 19 | /* 20 | Constructor for Furniture 21 | */ 22 | ItemManager::ItemManager() : 23 | id_lookup(ItemDao::getItemDefinitions()), 24 | interactor_manager(new InteractorManager()) { 25 | 26 | std::map interaction_types; 27 | 28 | for (auto furniture : this->id_lookup) { 29 | this->sprite_lookup[furniture.second->sprite_id] = furniture.second->id; 30 | } 31 | } 32 | 33 | /* 34 | Get item definitiion instance by item id 35 | 36 | @param item id 37 | @return item definition 38 | */ 39 | ItemDefinition *ItemManager::getDefinitionByID(int item_id) { 40 | 41 | if (this->id_lookup.count(item_id) > 0) { 42 | return this->id_lookup.find(item_id)->second; 43 | } 44 | 45 | return nullptr; 46 | } 47 | 48 | /* 49 | Get item definitiion instance by sprite id 50 | 51 | @param sprite id 52 | @return item definition 53 | */ 54 | ItemDefinition *ItemManager::getDefinitionBySpriteID(int item_id) { 55 | 56 | if (this->sprite_lookup.count(item_id) > 0) { 57 | return this->getDefinitionByID(sprite_lookup.find(item_id)->second); 58 | } 59 | 60 | return nullptr; 61 | } 62 | 63 | /* 64 | Item manager deconstructor 65 | */ 66 | ItemManager::~ItemManager() { 67 | delete this->interactor_manager; 68 | } 69 | -------------------------------------------------------------------------------- /src/game/item/ItemManager.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | 12 | #include "game/item/interactor/InteractorManager.h" 13 | #include "game/item/definitions/ItemDefinition.h" 14 | 15 | class ItemManager 16 | { 17 | public: 18 | ItemManager(); 19 | ~ItemManager(); 20 | 21 | ItemDefinition *getDefinitionByID(int item_id); 22 | ItemDefinition *getDefinitionBySpriteID(int item_id); 23 | 24 | InteractorManager *getInteractorManager() { return this->interactor_manager; } 25 | 26 | private: 27 | std::map id_lookup; 28 | std::map sprite_lookup; 29 | 30 | InteractorManager *interactor_manager; 31 | }; 32 | 33 | -------------------------------------------------------------------------------- /src/game/item/definitions/ItemType.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | enum ItemType { 3 | 4 | WALL_ITEM, 5 | FLOOR_ITEM 6 | }; -------------------------------------------------------------------------------- /src/game/item/interactor/BaseInteractor.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | class Item; 12 | class Room; 13 | class BaseInteractor 14 | { 15 | 16 | public: 17 | virtual void onInteract(Room *room, Item *item) = 0; 18 | virtual ~BaseInteractor() {} 19 | }; -------------------------------------------------------------------------------- /src/game/item/interactor/InteractorManager.cpp: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Icarus - A multi-platform C++ server 4 | * 5 | * Copyright 2016 Alex "Quackster" Miller 6 | * 7 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 8 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 9 | */ 10 | #pragma once 11 | #include 12 | 13 | #include "InteractorManager.h" 14 | 15 | #include "interactors/DefaultInteractor.h" 16 | #include "interactors/GateInteractor.h" 17 | 18 | /* 19 | Constructor for Interactor Manager 20 | 21 | Initialises the list for storing item interaction types 22 | */ 23 | InteractorManager::InteractorManager() { 24 | this->interactors["default"] = new DefaultInteractor(); 25 | this->interactors["gate"] = new GateInteractor(); 26 | } 27 | 28 | /* 29 | Gets the interactor for a interaction type, will return nullptr if nothing was supplied 30 | 31 | @return base interactor 32 | */ 33 | BaseInteractor *InteractorManager::getInteractor(std::string interaction_type) { 34 | 35 | if (this->interactors.count(interaction_type) > 0) { 36 | return this->interactors.find(interaction_type)->second; 37 | } 38 | 39 | return nullptr; 40 | } 41 | 42 | /* 43 | Deconstructor for Interactor Manager 44 | 45 | Deletes list for storing item interaction types 46 | */ 47 | InteractorManager::~InteractorManager() { 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/game/item/interactor/InteractorManager.h: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Icarus - A multi-platform C++ server 4 | * 5 | * Copyright 2016 Alex "Quackster" Miller 6 | * 7 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 8 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 9 | */ 10 | #pragma once 11 | #include 12 | #include "BaseInteractor.h" 13 | 14 | class InteractorManager 15 | { 16 | public: 17 | InteractorManager(); 18 | ~InteractorManager(); 19 | BaseInteractor *getInteractor(std::string interaction_type); 20 | 21 | private: 22 | std::map interactors; 23 | }; 24 | 25 | -------------------------------------------------------------------------------- /src/game/item/interactor/interactors/DefaultInteractor.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "misc/Utilities.h" 11 | 12 | #include "game/room/Room.h" 13 | 14 | #include "game/item/Item.h" 15 | #include "game/item/definitions/ItemDefinition.h" 16 | #include "game/item/interactor/BaseInteractor.h" 17 | 18 | class DefaultInteractor : public BaseInteractor { 19 | 20 | public: 21 | DefaultInteractor() { } 22 | 23 | void onInteract(Room *room, Item *item) { 24 | 25 | int modes = item->getDefinition()->interaction_modes_count; 26 | int current_mode = Utilities::isNumber(item->extra_data) ? stoi(item->extra_data) : 0; 27 | 28 | if (current_mode >= modes) { 29 | current_mode = 0; 30 | } 31 | else { 32 | current_mode++; 33 | } 34 | 35 | item->extra_data = std::to_string(current_mode); 36 | item->updateStatus(); 37 | item->save(); 38 | } 39 | }; -------------------------------------------------------------------------------- /src/game/item/interactor/interactors/GateInteractor.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "misc/Utilities.h" 11 | 12 | #include "boot/Icarus.h" 13 | #include "game/room/Room.h" 14 | 15 | #include "game/item/Item.h" 16 | #include "game/item/definitions/ItemDefinition.h" 17 | #include "game/item/interactor/BaseInteractor.h" 18 | 19 | class GateInteractor : public BaseInteractor { 20 | 21 | public: 22 | GateInteractor() { } 23 | 24 | void onInteract(Room *room, Item *item) { 25 | 26 | // Call default interactor, but here we need to re-do the collision map because 27 | // it's a gate! 28 | 29 | BaseInteractor *base = Icarus::getGame()->getItemManager()->getInteractorManager()->getInteractor("default"); 30 | base->onInteract(room, item); 31 | 32 | // Redo collision map to allow people to walk through, or block people! 33 | room->getDynamicModel()->regenerateCollisionMaps(); 34 | } 35 | }; -------------------------------------------------------------------------------- /src/game/item/inventory/Inventory.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | 12 | #include "game/item/definitions/ItemType.h" 13 | 14 | class Item; 15 | class Player; 16 | class Inventory { 17 | 18 | public: 19 | Inventory(Player *player, std::vector items); 20 | ~Inventory(); 21 | 22 | void update(); 23 | void addItem(Item *item); 24 | void removeItem(Item *item, bool delete_from_database = true); 25 | 26 | Item *getItem(int item_id); 27 | std::vector getItems(ItemType type); 28 | std::vector getItems() { return this->items; } 29 | 30 | private: 31 | Player *player; 32 | std::vector items; 33 | 34 | }; -------------------------------------------------------------------------------- /src/game/messenger/Messenger.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | 12 | class MessengerUser; 13 | class Player; 14 | class Messenger { 15 | 16 | private: 17 | 18 | int user_id; 19 | Player *player; 20 | 21 | std::map friends; 22 | std::map requests; 23 | 24 | public: 25 | Messenger(Player *player, int user_id, std::map friends, std::map requests); 26 | ~Messenger(); 27 | MessengerUser *getRequest(int user_id); 28 | MessengerUser *getFriend(int user_id); 29 | bool hasRequest(int id); 30 | bool isFriend(int id); 31 | void removeRequest(int user_id); 32 | void removeFriend(int user_id); 33 | void sendStatus(bool force_offline); 34 | void send(const MessageComposer &composer); 35 | 36 | std::map &getFriends() { 37 | return friends; 38 | } 39 | 40 | std::map &getRequests() { 41 | return requests; 42 | } 43 | 44 | void clearFriends(); 45 | void clearRequests(); 46 | bool initialised; 47 | }; -------------------------------------------------------------------------------- /src/game/messenger/MessengerUser.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/streams/Response.h" 11 | 12 | class Player; 13 | class MessengerUser { 14 | 15 | private: 16 | int user_id; 17 | std::shared_ptr details; 18 | Player *session; 19 | 20 | 21 | public: 22 | MessengerUser(int user_id); 23 | ~MessengerUser(); 24 | 25 | void update(); 26 | void serialise(Response &response, const bool force_offline, bool is_update = true); 27 | void serialiseSearch(Response &response); 28 | bool inRoom(); 29 | 30 | Player *getPlayer() { 31 | return session; 32 | }; 33 | 34 | std::shared_ptr getDetails() { return details; }; 35 | bool isOnline() { this->update(); return session != nullptr; } 36 | 37 | bool visible_status; 38 | }; -------------------------------------------------------------------------------- /src/game/navigator/NavigatorCategory.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | 12 | struct NavigatorCategory { 13 | int id; 14 | std::string name; 15 | int minimum_rank; 16 | }; 17 | 18 | -------------------------------------------------------------------------------- /src/game/navigator/NavigatorManager.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | #include 12 | 13 | #include "game/navigator/NavigatorTab.h" 14 | #include "game/navigator/NavigatorCategory.h" 15 | 16 | #include "game/navigator/populators/RoomPopulator.h" 17 | 18 | class NavigatorManager 19 | { 20 | public: 21 | NavigatorManager(); 22 | ~NavigatorManager(); 23 | 24 | NavigatorTab *getTab(std::string tab_name); 25 | std::vector getParentTabs(); 26 | NavigatorCategory *getCategoryById(int category_id); 27 | std::vector getTabs() { return tabs; } 28 | std::vector getCategories() { return categories; } 29 | RoomPopulator *getPopulator(std::string name); 30 | 31 | 32 | private: 33 | std::vector tabs; 34 | std::vector categories; 35 | std::map room_populators; 36 | }; 37 | 38 | -------------------------------------------------------------------------------- /src/game/navigator/NavigatorTab.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #include "stdafx.h" 10 | 11 | #include "boot/Icarus.h" 12 | #include "game/navigator/NavigatorTab.h" 13 | 14 | /* 15 | Constructor for Navigator tab 16 | */ 17 | NavigatorTab::NavigatorTab(int id, int child_id, std::string tab_name, std::string title, char button_type, bool closed, bool thumbnail, std::string populator_name) : 18 | id(id), child_id(child_id), tab_name(tab_name), title(title), button_type(button_type), closed(closed), thumbnail(thumbnail), populator(populator_name) { } 19 | 20 | /* 21 | Get all child tabs under this tab 22 | 23 | @return list of child tabs 24 | */ 25 | std::vector NavigatorTab::getChildTabs() { 26 | 27 | std::vector tabs = std::vector(); 28 | 29 | for (auto tab : Icarus::getGame()->getNavigatorManager()->getTabs()) { 30 | if (tab->getChildId() == this->id) { 31 | tabs.push_back(tab); 32 | } 33 | } 34 | 35 | return tabs; 36 | } 37 | 38 | 39 | /* 40 | Deconstructor for navigator tab 41 | */ 42 | NavigatorTab::~NavigatorTab() 43 | { 44 | } 45 | -------------------------------------------------------------------------------- /src/game/navigator/NavigatorTab.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | 12 | class NavigatorTab 13 | { 14 | public: 15 | NavigatorTab(int id, int childId, std::string tab_name, std::string title, char button_type, bool closed, bool thumbnail, std::string populator); 16 | ~NavigatorTab(); 17 | 18 | std::vector getChildTabs(); 19 | 20 | const int &getId() const { return id; } 21 | const int &getChildId() const { return child_id; } 22 | const std::string &getTabName() const { return tab_name; } 23 | const std::string &getTitle() const { return title; } 24 | const char &getButtonType() const { return button_type; } 25 | const bool &getClosed() const { return closed; } 26 | const bool &getThumbnail() const { return thumbnail; } 27 | const std::string &getPopulatorName() const { return populator; } 28 | 29 | private: 30 | int id; 31 | int child_id; 32 | std::string tab_name; 33 | std::string title; 34 | char button_type; 35 | bool closed; 36 | bool thumbnail; 37 | std::string populator; 38 | }; 39 | 40 | -------------------------------------------------------------------------------- /src/game/navigator/populators/DefaultPopulator.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | 12 | #include "RoomPopulator.h" 13 | 14 | class DefaultPopulator : public RoomPopulator { 15 | 16 | public: 17 | DefaultPopulator() { } 18 | 19 | std::vector populate(bool room_limit, Player* player) { 20 | 21 | std::vector rooms; 22 | return rooms; 23 | } 24 | }; -------------------------------------------------------------------------------- /src/game/navigator/populators/DisposablePopulator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class Room; 6 | class DisposablePopulator 7 | { 8 | 9 | public: 10 | virtual ~DisposablePopulator() {} 11 | virtual void dispose(std::vector rooms) = 0; 12 | }; -------------------------------------------------------------------------------- /src/game/navigator/populators/FriendsPopulator.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | 12 | #include "boot/Icarus.h" 13 | #include "dao/NavigatorDao.h" 14 | 15 | #include "DisposablePopulator.h" 16 | #include "RoomPopulator.h" 17 | #include "FriendsPopulator.h" 18 | 19 | class FriendsPopulator : public RoomPopulator, public DisposablePopulator { 20 | 21 | public: 22 | FriendsPopulator() { } 23 | 24 | std::vector populate(bool room_limit, Player* player) { 25 | 26 | std::vector rooms = NavigatorDao::getPreviewRooms(NAVIGATOR_FRIENDS_ROOMS, player->getDetails()->id); 27 | return rooms; 28 | } 29 | 30 | /* 31 | Since this class only uses temporary pointers, we dispose them when they're no longer needed. 32 | The system fundementally uses pointers for rooms - so this is required in order to stop memory leaks. 33 | 34 | @param room list 35 | @return none 36 | */ 37 | void dispose(std::vector rooms) { 38 | for (Room *room : rooms) { 39 | delete room; 40 | } 41 | } 42 | }; -------------------------------------------------------------------------------- /src/game/navigator/populators/MyRoomPopulator.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | 12 | #include "boot/Icarus.h" 13 | #include "RoomPopulator.h" 14 | 15 | class MyRoomPopulator : public RoomPopulator { 16 | 17 | public: 18 | MyRoomPopulator() { } 19 | 20 | std::vector populate(bool room_limit, Player* player) { 21 | 22 | std::vector rooms = Icarus::getGame()->getRoomManager()->getPlayerRooms(player->getDetails()->id); 23 | this->sort(rooms); 24 | return rooms; 25 | } 26 | }; -------------------------------------------------------------------------------- /src/game/navigator/populators/OfficialRoomPopulator.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | 12 | #include "RoomPopulator.h" 13 | 14 | class OfficialRoomPopulator : public RoomPopulator { 15 | 16 | public: 17 | OfficialRoomPopulator() { } 18 | std::vector populate(bool room_limit, Player* player) { 19 | 20 | std::vector rooms; 21 | 22 | for (auto room : Icarus::getGame()->getRoomManager()->getPublicRooms()) { 23 | 24 | rooms.push_back(room); 25 | } 26 | 27 | this->sort(rooms); 28 | return rooms; 29 | } 30 | }; -------------------------------------------------------------------------------- /src/game/navigator/populators/PopularPopulator.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | 12 | #include "RoomPopulator.h" 13 | 14 | class PopularPopulator : public RoomPopulator { 15 | 16 | public: 17 | PopularPopulator() { } 18 | std::vector populate(bool room_limit, Player* player) { 19 | 20 | std::vector rooms; 21 | 22 | for (auto kvp : Icarus::getGame()->getRoomManager()->getRooms()) { 23 | 24 | Room *room = kvp.second; 25 | 26 | if (room->getData()->users_now == 0) { 27 | continue; 28 | } 29 | 30 | if (!room->getData()->private_room) { 31 | continue; 32 | } 33 | 34 | if (room->getData()->state == RoomState::INVISIBLE) { 35 | if (!room->hasRights(player)) { 36 | continue; 37 | } 38 | } 39 | 40 | rooms.push_back(room); 41 | } 42 | 43 | this->sort(rooms); 44 | return rooms; 45 | } 46 | }; -------------------------------------------------------------------------------- /src/game/navigator/populators/RoomPopulator.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | 12 | #include "game/player/Player.h" 13 | #include "game/room/Room.h" 14 | 15 | struct PopulationSorter { 16 | inline bool operator() (Room* struct1, Room* struct2) { 17 | return struct1->getData()->users_now > struct2->getData()->users_now;//(struct1.key < struct2.key); 18 | } 19 | }; 20 | 21 | class RoomPopulator 22 | { 23 | 24 | public: 25 | virtual ~RoomPopulator() {} 26 | virtual std::vector populate(bool room_limit, Player *player) = 0; 27 | 28 | void sort(std::vector &rooms) { 29 | std::sort(rooms.begin(), rooms.end(), PopulationSorter()); 30 | } 31 | }; -------------------------------------------------------------------------------- /src/game/pathfinder/Pathfinder.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | 12 | #include "game/room/Room.h" 13 | #include "game/pathfinder/Position.h" 14 | #include "game/pathfinder/PathfinderNode.h" 15 | 16 | class Pathfinder 17 | { 18 | public: 19 | ~Pathfinder(); 20 | 21 | 22 | static std::deque makePath(Position start, Position end, Room *room); 23 | static std::shared_ptr makePathReversed(Position start, Position end, Room *room); 24 | static bool isValidStep(Room *room, Position current, Position tmp, bool is_final_move); 25 | 26 | static std::vector getPoints() { 27 | 28 | std::vector points; 29 | 30 | points.push_back(Position(0, -1)); 31 | points.push_back(Position(0, 1)); 32 | points.push_back(Position(1, 0)); 33 | points.push_back(Position(-1, 0)); 34 | points.push_back(Position(1, -1)); 35 | points.push_back(Position(-1, 1)); 36 | points.push_back(Position(1, 1)); 37 | points.push_back(Position(-1, -1)); 38 | 39 | return points; 40 | } 41 | }; 42 | 43 | -------------------------------------------------------------------------------- /src/game/pathfinder/PathfinderNode.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #include "stdafx.h" 10 | #include "PathfinderNode.h" 11 | 12 | 13 | PathfinderNode::PathfinderNode() : 14 | position(Position(0, 0)), 15 | node(nullptr), 16 | in_open(false), 17 | in_close(false), 18 | cost(99999999) { } 19 | 20 | PathfinderNode::PathfinderNode(Position position) : 21 | node(nullptr), 22 | in_open(false), 23 | in_close(false), 24 | position(position), 25 | cost(99999999) { } 26 | 27 | PathfinderNode::~PathfinderNode() { } 28 | -------------------------------------------------------------------------------- /src/game/pathfinder/PathfinderNode.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "game/room/Room.h" 11 | #include "Position.h" 12 | 13 | class PathfinderNode 14 | { 15 | 16 | public: 17 | PathfinderNode(); 18 | PathfinderNode(Position position); 19 | ~PathfinderNode(); 20 | 21 | std::shared_ptr node; 22 | bool in_open; 23 | bool in_close; 24 | Position position; 25 | int cost; 26 | }; 27 | 28 | -------------------------------------------------------------------------------- /src/game/pathfinder/Position.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #include "stdafx.h" 10 | #include "game/pathfinder/Position.h" 11 | 12 | Position::Position() : 13 | x(-999), 14 | y(-999), 15 | z(-999) { } 16 | 17 | Position::Position(int x, int y) : 18 | x(x), 19 | y(y) { } 20 | 21 | Position::Position(int x, int y, int z) : 22 | x(x), 23 | y(y), 24 | z(z) { } 25 | 26 | Position::~Position() { } 27 | -------------------------------------------------------------------------------- /src/game/pathfinder/Position.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | 12 | class Position 13 | { 14 | public: 15 | Position(); 16 | Position(int x, int y); 17 | Position(int x, int y, int z); 18 | ~Position(); 19 | 20 | Position addPoint(Position point) { 21 | return Position(x + point.x, y + point.y); 22 | } 23 | 24 | Position subtractPoint(Position point) { 25 | return Position(x - point.x, y - point.y); 26 | } 27 | 28 | int getDistance(Position point) { 29 | int dx = x - point.x; 30 | int dy = y - point.y; 31 | return (dx * dx) + (dy * dy); 32 | } 33 | 34 | bool sameAs(Position point) { 35 | return x == point.x && y == point.y; 36 | } 37 | 38 | bool isEmpty() { 39 | return x == -999 && y == -999; 40 | } 41 | 42 | std::string toString() { 43 | return std::to_string(x) + ", " + std::to_string(y); 44 | } 45 | 46 | int x; 47 | int y; 48 | int z; 49 | }; 50 | 51 | -------------------------------------------------------------------------------- /src/game/player/PlayerManager.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "game/player/Player.h" 11 | 12 | #include 13 | 14 | class PlayerManager 15 | { 16 | 17 | public: 18 | PlayerManager(); 19 | ~PlayerManager(); 20 | void addSession(Player *session, int connection_id); 21 | void removeSession(int connection_id); 22 | bool containsSession(int connection_id); 23 | Player *getSession(int connection_id); 24 | 25 | Player *getPlayerById(int user_id); 26 | Player *getPlayerByUsername(std::string user_name); 27 | 28 | std::map *getPlayersIDLookup() { return this->authenticated_sessions_id; } 29 | std::map *getPlayersUsernameLookup() { return this->authenticated_sessions_username; } 30 | 31 | private: 32 | std::map *player_connections; 33 | std::map *authenticated_sessions_id; 34 | std::map *authenticated_sessions_username; 35 | }; -------------------------------------------------------------------------------- /src/game/room/RoomData.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | #include 12 | 13 | #include "model/RoomModel.h" 14 | 15 | class Room; 16 | 17 | class RoomState { 18 | 19 | public: 20 | static const int OPEN = 0; 21 | static const int INVISIBLE = 3; 22 | static const int DOORBELL = 1; 23 | static const int PASSWORD = 2; 24 | }; 25 | 26 | struct RoomData { 27 | int id; 28 | std::string name; 29 | char room_type; 30 | std::string thumbnail; 31 | int owner_id; 32 | Player *owner; 33 | std::string owner_name; 34 | int group_id; 35 | std::string description; 36 | std::string password; 37 | int users_now = 0; 38 | int users_max; 39 | RoomModel *model; 40 | std::string wallpaper; 41 | std::string floor; 42 | std::string outside; 43 | std::vector tags; 44 | int trade_state; 45 | int state; 46 | int score; 47 | int category; 48 | bool allow_pets; 49 | bool allow_pets_eat; 50 | bool allow_walkthrough; 51 | int floor_thickness; 52 | int wall_thickness; 53 | bool hide_wall; 54 | int wall_height = -1; 55 | int chat_mode; 56 | int chat_size; 57 | int chat_speed; 58 | int chat_flood; 59 | int chat_distance; 60 | int who_can_mute; 61 | int who_can_kick; 62 | int who_can_ban; 63 | int virtual_id = 0; 64 | std::vector user_rights; 65 | bool private_room = true; 66 | }; 67 | 68 | -------------------------------------------------------------------------------- /src/game/room/RoomManager.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | 12 | #include "game/room/misc/RoomNewbie.h" 13 | #include "game/room/Room.h" 14 | #include "game/room/model/RoomModel.h" 15 | 16 | class RoomManager 17 | { 18 | public: 19 | RoomManager(); 20 | ~RoomManager(); 21 | 22 | 23 | 24 | void createPlayerRooms(int user_id); 25 | std::vector getPlayerRooms(int user_id); 26 | 27 | RoomModel *getModel(std::string model_id); 28 | bool hasRoom(int room_id); 29 | Room *getRoom(int room_id); 30 | void addRoom(Room *room); 31 | void deleteRoom(int room_id); 32 | 33 | std::map &getRooms() { return rooms; } 34 | 35 | std::vector getNewbieRoomTemplates() { return rooms_newbie; } 36 | std::vector &getPublicRooms() { return public_rooms; } 37 | 38 | private: 39 | std::map rooms; 40 | std::vector public_rooms; 41 | 42 | std::vector rooms_newbie; 43 | std::map models; 44 | }; 45 | 46 | -------------------------------------------------------------------------------- /src/game/room/misc/RoomNewbie.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | #include 12 | 13 | #include "RoomNewbieItem.h" 14 | 15 | struct RoomNewbie { 16 | 17 | std::string model; 18 | std::string wallpaper; 19 | std::string floorpaper; 20 | std::vector items; 21 | }; -------------------------------------------------------------------------------- /src/game/room/misc/RoomNewbieItem.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | #include 12 | 13 | class ItemDefinition; 14 | struct RoomNewbieItem { 15 | 16 | int item_id; 17 | std::string position; 18 | 19 | int x = -1; 20 | int y = -1; 21 | int z; 22 | int rotation = 0; 23 | 24 | ItemDefinition *definition; 25 | }; -------------------------------------------------------------------------------- /src/game/room/model/DynamicModel.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | #include 12 | #include 13 | 14 | class Room; 15 | class Item; 16 | class RoomTile; 17 | class DynamicModel 18 | { 19 | 20 | public: 21 | DynamicModel(Room *room); 22 | 23 | void load(); 24 | void regenerateCollisionMaps(); 25 | void checkHighestItem(Item *item, int x, int y); 26 | 27 | Item *getItem(int x, int y); 28 | RoomTile &getTile(int x, int y); 29 | double getStackHeight(int x, int y); 30 | 31 | void removeItem(Item *item); 32 | void addItem(Item *item); 33 | void updateItemPosition(Item *item, bool rotation_only = false); 34 | void handleItemAdjustment(Item *item, bool rotation_only = false); 35 | bool isValidTile(int x, int y); 36 | 37 | ~DynamicModel(); 38 | 39 | private: 40 | Room *room; 41 | std::map> tiles; 42 | 43 | int map_size_x; 44 | int map_size_y; 45 | }; 46 | 47 | -------------------------------------------------------------------------------- /src/game/room/model/RoomModel.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | #include 12 | 13 | class RoomModel 14 | { 15 | 16 | public: 17 | const static int OPEN = 0; 18 | const static int CLOSED = 1; 19 | 20 | RoomModel(std::string name, std::string heightmap, int door_x, int door_y, int door_z, int door_rotation); 21 | ~RoomModel(); 22 | 23 | std::string getSquareChar(int x, int y); 24 | double getSquareHeight(int x, int y); 25 | const bool isValidSquare(int x, int y); 26 | std::map> &getSquares(); 27 | 28 | const int getRandomX(); 29 | const int getRandomY(); 30 | 31 | std::string name; 32 | std::string height_map; 33 | std::string floor_map; 34 | 35 | int door_x; 36 | int door_y; 37 | int door_z; 38 | int door_rotation; 39 | int map_size_x; 40 | int map_size_y; 41 | 42 | private: 43 | std::map> square_chars; 44 | std::map> squares; 45 | std::map> square_height; 46 | }; -------------------------------------------------------------------------------- /src/game/room/model/Rotation.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | 10 | #include "stdafx.h" 11 | #include "game/room/model/Rotation.h" 12 | 13 | int Rotation::getRotation(int current_x, int current_y, int new_x, int new_y) { 14 | 15 | int rotation = 0; 16 | 17 | if (current_x > new_x && current_y > new_y) { 18 | rotation = 7; 19 | } 20 | else if (current_x < new_x && current_y < new_y) { 21 | rotation = 3; 22 | } 23 | else if (current_x > new_x && current_y < new_y) { 24 | rotation = 5; 25 | } 26 | else if (current_x < new_x && current_y > new_y) { 27 | rotation = 1; 28 | } 29 | else if (current_x > new_x) { 30 | rotation = 6; 31 | } 32 | else if (current_x < new_x) { 33 | rotation = 2; 34 | } 35 | else if (current_y < new_y) { 36 | rotation = 4; 37 | } 38 | else if (current_y > new_y) { 39 | rotation = 0; 40 | } 41 | 42 | return rotation; 43 | } -------------------------------------------------------------------------------- /src/game/room/model/Rotation.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | 11 | class Rotation { 12 | 13 | public: 14 | static int getRotation(int current_x, int current_y, int new_x, int new_y); 15 | }; -------------------------------------------------------------------------------- /src/game/room/model/tile/RoomTile.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | 10 | #include "stdafx.h" 11 | 12 | #include "RoomTile.h" 13 | #include "game/room/Room.h" 14 | 15 | /* 16 | Constructors for room tile 17 | 18 | @param Room pointer 19 | */ 20 | RoomTile::RoomTile() { } 21 | 22 | RoomTile::RoomTile(Room *room) 23 | : room(room) { } 24 | 25 | /* 26 | Return the items list in this tile by reference 27 | 28 | @return vector Item ptr 29 | */ 30 | std::vector &RoomTile::getItems() { 31 | return this->items; 32 | } 33 | 34 | /* 35 | Returns the highest Item found on this tile 36 | 37 | @return Item pointer 38 | */ 39 | Item *RoomTile::getHighestItem() { 40 | return this->highest_item; 41 | } 42 | 43 | /* 44 | Sets the highest item defined in this tile 45 | 46 | @param Item pointer 47 | @return none 48 | */ 49 | void RoomTile::setHighestItem(Item *item) { 50 | this->highest_item = item; 51 | } 52 | 53 | RoomTile::~RoomTile() { } -------------------------------------------------------------------------------- /src/game/room/model/tile/RoomTile.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | 12 | class Item; 13 | class Room; 14 | class RoomTile { 15 | 16 | public: 17 | RoomTile(); 18 | RoomTile(Room *room); 19 | ~RoomTile(); 20 | 21 | double height = 0.0; 22 | 23 | std::vector &getItems(); 24 | Item *getHighestItem(); 25 | void setHighestItem(Item *item); 26 | 27 | 28 | private: 29 | Room *room; 30 | std::vector items; 31 | Item *highest_item = nullptr; 32 | }; -------------------------------------------------------------------------------- /src/game/room/tasks/RoomRunnable.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | 12 | #include "thread/Runnable.h" 13 | #include "game/room/Room.h" 14 | 15 | 16 | class RoomRunnable : public Runnable { 17 | 18 | public: 19 | RoomRunnable(Room *room); 20 | void run(); 21 | void processEntity(Entity *entity); 22 | bool hasTicked(int seconds) { return tick % (seconds * 2) == 0; } 23 | Room *room; 24 | std::mutex mtx; 25 | std::vector chat_messages; 26 | int tick; 27 | 28 | }; -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #include "stdafx.h" 10 | #include "boot/Icarus.h" 11 | 12 | int main(int argc, char* argv[]) { 13 | 14 | bool close_when_crash = false; 15 | 16 | if (argc > 1) { 17 | if (std::string(argv[1]) == "-close") { 18 | close_when_crash = true; 19 | } 20 | } 21 | 22 | try { 23 | Icarus::boot(); 24 | } catch (std::exception& e) { 25 | cout << endl << " Error occurred: " << e.what() << endl; 26 | } 27 | 28 | if (!close_when_crash) { 29 | cout << endl << " Server has crashed, if you want the program to close when it crashes, start it with the command argument: -close" << endl; 30 | while (true); 31 | } 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /src/misc/Configuration.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | #include 12 | 13 | class Configuration 14 | { 15 | 16 | public: 17 | Configuration(std::string file); 18 | //~Configuration(); 19 | std::string getString(std::string key); 20 | int getInt(std::string key); 21 | bool getBool (std::string key); 22 | std::map getValues(); 23 | 24 | private: 25 | std::string file; 26 | std::map values; 27 | void parse(); 28 | }; 29 | 30 | -------------------------------------------------------------------------------- /src/misc/Utilities.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | #include 12 | 13 | class Utilities 14 | { 15 | 16 | private: 17 | Utilities() { }; 18 | 19 | public: 20 | static std::vector split(const std::string &s, char delim); 21 | static std::string trim(std::string &str); 22 | static bool isNumber(const std::string& s); 23 | static std::string escape(std::string &input, bool allow_breaks = false, bool strip_non_alphanumeric = false, bool replace_spaces = false); 24 | static std::string removeNonAlphanumeric(std::string &input); 25 | static std::string replaceChar(std::string &str, char ch1, char ch2); 26 | static std::string removeChar(std::string &s, char ch1); 27 | static std::string join(std::vector strings, std::string delim); 28 | static std::vector Utilities::readLines(std::string file_path); 29 | static std::string base64_encode(const std::string &in); 30 | static std::string base64_decode(const std::string &in); 31 | static bool contains(std::string haystack, std::string needle); 32 | static std::string uppercase(std::string str); 33 | static bool isEqual(double x, double y); 34 | 35 | }; -------------------------------------------------------------------------------- /src/network/NetworkConnection.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | #include "communication/streams/Request.h" 17 | #include "communication/streams/Response.h" 18 | #include "communication/outgoing/MessageComposer.h" 19 | 20 | 21 | using boost::asio::ip::tcp; 22 | 23 | class NetworkConnection : public std::enable_shared_from_this 24 | { 25 | 26 | public: 27 | NetworkConnection(int connection_id, tcp::socket socket); 28 | ~NetworkConnection(); 29 | void recieveData(); 30 | void handleData(Request request); 31 | void send(Response response); 32 | void send(const MessageComposer &composer); 33 | void writeData(const char* data, int length); 34 | void writeData(std::string data) { this->writeData(data.c_str(), (int)data.length() + 1); } 35 | void sendPolicy(); 36 | int getConnectionId();// { return connectionID; }; 37 | bool getConnectionState();// { return connectionState; }; 38 | void setConnectionState(bool connectionState);// { this->connectionState = connectionState; }; 39 | tcp::socket &getSocket() { return this->socket; } 40 | 41 | private: 42 | int connection_id; 43 | bool connection_state; 44 | tcp::socket socket; 45 | 46 | enum { maxLength = 256 }; 47 | char buffer[maxLength]; 48 | }; 49 | -------------------------------------------------------------------------------- /src/network/NetworkServer.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #include "stdafx.h" 10 | #include "NetworkServer.h" 11 | 12 | /* 13 | Network server constructor 14 | 15 | @return none 16 | */ 17 | NetworkServer::NetworkServer(boost::asio::io_service& io_service, std::string host, short port) : 18 | acceptor(io_service, tcp::endpoint(tcp::endpoint(tcp::v4(), port))), /*boost::asio::ip::address::from_string(host), port)),//*/ 19 | socket(io_service), 20 | connection_id(0) { 21 | 22 | this->startAccept(); 23 | } 24 | 25 | /* 26 | Network server deconstructor 27 | 28 | @return none 29 | */ 30 | NetworkServer::~NetworkServer() { 31 | 32 | } 33 | 34 | /* 35 | Start accepting clients 36 | 37 | @return none 38 | */ 39 | void NetworkServer::startAccept() { 40 | 41 | acceptor.async_accept(socket, [this](boost::system::error_code ec) { 42 | 43 | if (!ec) { 44 | std::shared_ptr connection = std::make_shared(this->connection_id++, std::move(socket)); 45 | connection->recieveData(); // start with 4 bytes at first 46 | } 47 | 48 | this->startAccept(); 49 | }); 50 | } 51 | 52 | /** 53 | Stops network connection from listening for more packets and deletes it from memory 54 | @param NetworkConnection pointer to delete 55 | @return none 56 | */ 57 | void NetworkServer::removeNetworkConnection(NetworkConnection *connection) { 58 | 59 | // Tell connnection to stop looping for more incoming packets 60 | connection->setConnectionState(false); 61 | } -------------------------------------------------------------------------------- /src/network/NetworkServer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "game/player/Player.h" 11 | #include "communication/incoming/MessageHandler.h" 12 | 13 | class NetworkServer 14 | { 15 | public: 16 | NetworkServer(boost::asio::io_service& io_service, std::string host, short port); 17 | ~NetworkServer(); 18 | void startAccept(); 19 | void removeNetworkConnection(NetworkConnection *connection); 20 | 21 | private: 22 | int connection_id; 23 | tcp::acceptor acceptor; 24 | tcp::socket socket; 25 | }; 26 | -------------------------------------------------------------------------------- /src/network/rcon/RconConnection.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | using boost::asio::ip::tcp; 18 | 19 | class RconConnection : public std::enable_shared_from_this 20 | { 21 | 22 | public: 23 | RconConnection(tcp::socket socket); 24 | ~RconConnection(); 25 | void recieveData(); 26 | void sendResponse(std::string content); 27 | void writeData(const char* data, int length); 28 | void sendPolicy(); 29 | bool getConnectionState();// { return connectionState; }; 30 | void setConnectionState(bool connectionState);// { this->connectionState = connectionState; }; 31 | tcp::socket &getSocket() { return this->socket; } 32 | 33 | private: 34 | bool connection_state; 35 | tcp::socket socket; 36 | enum { maxLength = 512 }; 37 | char buffer[maxLength]; 38 | }; 39 | -------------------------------------------------------------------------------- /src/network/rcon/RconServer.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #include "stdafx.h" 10 | #include "RconServer.h" 11 | #include "RconConnection.h" 12 | 13 | /* 14 | Network server constructor 15 | 16 | @return none 17 | */ 18 | RconServer::RconServer(boost::asio::io_service& io_service, std::string host, short port) : 19 | acceptor(io_service, tcp::endpoint(boost::asio::ip::address::from_string(host), port)),//tcp::endpoint(tcp::v4(), port)), 20 | socket(io_service), 21 | connection_id(0) { 22 | 23 | this->startAccept(); 24 | } 25 | 26 | /* 27 | Network server deconstructor 28 | 29 | @return none 30 | */ 31 | RconServer::~RconServer() { 32 | 33 | } 34 | 35 | /* 36 | Start accepting clients 37 | 38 | @return none 39 | */ 40 | void RconServer::startAccept() { 41 | 42 | acceptor.async_accept(socket, [this](boost::system::error_code ec) { 43 | 44 | if (!ec) { 45 | std::shared_ptr connection = std::make_shared(std::move(socket)); 46 | connection->recieveData(); // start with 4 bytes at first 47 | } 48 | 49 | this->startAccept(); 50 | }); 51 | } -------------------------------------------------------------------------------- /src/network/rcon/RconServer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | 12 | #include "game/player/Player.h" 13 | 14 | class RconServer 15 | { 16 | public: 17 | RconServer(boost::asio::io_service& io_service, std::string host, short port); 18 | ~RconServer(); 19 | void startAccept(); 20 | 21 | private: 22 | int connection_id; 23 | tcp::acceptor acceptor; 24 | tcp::socket socket; 25 | }; 26 | -------------------------------------------------------------------------------- /src/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // Icarus.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | 7 | // TODO: reference any additional headers you need in STDAFX.H 8 | // and not in this file 9 | -------------------------------------------------------------------------------- /src/stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | // 5 | 6 | #pragma once 7 | 8 | #include 9 | 10 | using std::endl; 11 | using std::cout; 12 | 13 | #if defined(WIN32_LEAN_AND_MEAN) 14 | #include 15 | #endif 16 | 17 | // TODO: reference additional headers your program requires here 18 | -------------------------------------------------------------------------------- /src/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Including SDKDDKVer.h defines the highest available Windows platform. 4 | 5 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and 6 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /src/thread/BlockingQueue.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | template 15 | class BlockingQueue 16 | { 17 | private: 18 | std::mutex mutex; 19 | std::condition_variable condition; 20 | std::deque queue; 21 | public: 22 | 23 | std::deque getDeque() { return queue; } 24 | 25 | void push(T const& value) { 26 | { 27 | std::unique_lock lock(this->mutex); 28 | queue.push_front(value); 29 | } 30 | this->condition.notify_one(); 31 | } 32 | T pop() { 33 | std::unique_lock lock(this->mutex); 34 | this->condition.wait(lock, [=] { return !this->queue.empty(); }); 35 | T rc(std::move(this->queue.back())); 36 | this->queue.pop_back(); 37 | return rc; 38 | } 39 | 40 | /* bool empty() { 41 | std::unique_lock lock(this->d_mutex); 42 | bool check = this->d_queue.empty(); 43 | return check; 44 | }*/ 45 | }; -------------------------------------------------------------------------------- /src/thread/ExecutorService.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include 11 | #include 12 | 13 | using std::endl; 14 | using std::cout; 15 | 16 | #include "BlockingQueue.h" 17 | #include "Runnable.h" 18 | 19 | class ExecutorService 20 | { 21 | public: 22 | ExecutorService(int threads, std::chrono::milliseconds duration); 23 | ~ExecutorService(); 24 | 25 | static ExecutorService *createSchedulerService(int threads); 26 | static ExecutorService *createSchedulerService(int threads, std::chrono::milliseconds duration); 27 | 28 | void schedule(std::shared_ptr runnable); 29 | void stop() { this->running = false; } 30 | 31 | private: 32 | bool running; 33 | 34 | std::chrono::milliseconds duration; 35 | 36 | std::vector threads; 37 | BlockingQueue> tasks; 38 | std::vector cancelled_threads; 39 | 40 | void tick(); 41 | }; 42 | 43 | -------------------------------------------------------------------------------- /src/thread/Runnable.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Icarus - A multi-platform C++ server 3 | * 4 | * Copyright 2016 Alex "Quackster" Miller 5 | * 6 | * Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 7 | * (see https://creativecommons.org/licenses/by-nc-sa/4.0/, or LICENSE.txt for a full license 8 | */ 9 | #pragma once 10 | #include "communication/outgoing/MessageComposer.h" 11 | 12 | 13 | class Runnable 14 | { 15 | 16 | public: 17 | virtual ~Runnable() {} 18 | virtual void run() = 0; 19 | }; --------------------------------------------------------------------------------