├── .gitignore ├── .gitmodules ├── LICENSE ├── README.md ├── bin ├── Data │ ├── ClientTable.csv │ ├── CodisData.csv │ ├── EpicPieceShop.csv │ ├── EventShop.csv │ ├── FamilyTotalWar.json │ ├── FamilyTotalWarMap.csv │ ├── GameModeList.csv │ ├── HonorMoneyShop.csv │ ├── Item.csv │ ├── ItemExpireTime.csv │ ├── MapList.csv │ ├── MatchOption.csv │ ├── Metadata_ReinforceItemsExp.bin │ ├── Metadata_Unk20.bin │ ├── Metadata_Unk3.bin │ ├── Metadata_Unk31.bin │ ├── Metadata_Unk43.bin │ ├── Metadata_Unk49.bin │ ├── Metadata_Unk54.bin │ ├── Metadata_Unk55.bin │ ├── Metadata_Unk8.bin │ ├── MileageShop.csv │ ├── ModeEvent.csv │ ├── ReinforceMaxEXP.csv │ ├── ReinforceMaxLv.csv │ ├── SQL │ │ ├── HoldBingoEvent.sql │ │ ├── HoldWeaponReleaseEvent.sql │ │ ├── Update_2.sql │ │ ├── Update_3.sql │ │ ├── Update_4.sql │ │ └── main.sql │ ├── WeaponProp.json │ ├── ZBCompetitive.json │ ├── ppsystem.json │ ├── progress_unlock.csv │ ├── scenariotx_common.json │ ├── scenariotx_dedi.json │ ├── shopitemlist_dedi.json │ ├── voxel_item.csv │ ├── voxel_list.csv │ └── weaponparts.csv ├── EventQuests.json ├── ItemBox.json ├── ItemRewards.json ├── RandomWeaponList.json ├── ServerConfig.json ├── Shop.json ├── WeaponPaints.json └── ZombieWarWeaponList.json ├── docs ├── codingstyle.md ├── diagrams │ ├── Activity - user login.jpg │ ├── Class - network.jpg │ ├── Communication - client connect.jpg │ ├── Deployment - server.jpg │ ├── Interation overview - client connect.jpg │ ├── Sequence - User login.jpg │ ├── Sequence - client connect.jpg │ ├── Use case - net code.jpg │ └── srv.vpp ├── documentation.md ├── doxygen │ └── Doxyfile ├── eventquests.md ├── glossary.md ├── itembox.md ├── itemrewards.md ├── randomweaponlist.md ├── serverconfig.md ├── serverconfiguration.md ├── shop.md ├── weaponpaints.md └── zombiewarweaponlist.md └── src ├── CMakeLists.txt ├── channel ├── channel.cpp ├── channel.h ├── channelserver.cpp └── channelserver.h ├── command.cpp ├── command.h ├── common ├── buffer.cpp ├── buffer.h ├── buildnum.cpp ├── buildnum.h ├── logger.cpp ├── logger.h ├── net │ └── netdefs.h ├── thread.cpp ├── thread.h ├── utils.cpp └── utils.h ├── crashdump.cpp ├── crashdump.h ├── csvtable.cpp ├── csvtable.h ├── definitions.h ├── event.h ├── gui ├── CMakeLists.txt ├── bandialog.cpp ├── bandialog.h ├── bandialog.ui ├── consoletab.cpp ├── consoletab.h ├── consoletab.ui ├── gui.cpp ├── gui.h ├── hwidbanlistdialog.cpp ├── hwidbanlistdialog.h ├── hwidbanlistdialog.ui ├── igui.h ├── ipbanlistdialog.cpp ├── ipbanlistdialog.h ├── ipbanlistdialog.ui ├── maintab.cpp ├── maintab.h ├── maintab.ui ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── noticedialog.cpp ├── noticedialog.h ├── noticedialog.ui ├── roomlisttab.cpp ├── roomlisttab.h ├── roomlisttab.ui ├── selectuserdialog.cpp ├── selectuserdialog.h ├── selectuserdialog.ui ├── sessiontab.cpp ├── sessiontab.h ├── sessiontab.ui ├── userbanlistdialog.cpp ├── userbanlistdialog.h ├── userbanlistdialog.ui ├── usercharacterdialog.cpp ├── usercharacterdialog.h └── usercharacterdialog.ui ├── interface ├── ichannelmanager.h ├── iclanmanager.h ├── idedicatedservermanager.h ├── ievent.h ├── ihostmanager.h ├── iitemmanager.h ├── iluckyitemmanager.h ├── imanager.h ├── iminigamemanager.h ├── ipacketmanager.h ├── iquestmanager.h ├── irankmanager.h ├── iroom.h ├── iserverinstance.h ├── ishopmanager.h ├── iuser.h ├── iuserdatabase.h ├── iusermanager.h ├── ivoxelmanager.h └── net │ ├── iextendedsocket.h │ └── iserverlistener.h ├── main.cpp ├── main.h ├── manager ├── channelmanager.cpp ├── channelmanager.h ├── clanmanager.cpp ├── clanmanager.h ├── dedicatedservermanager.cpp ├── dedicatedservermanager.h ├── hostmanager.cpp ├── hostmanager.h ├── itemmanager.cpp ├── itemmanager.h ├── luckyitemmanager.cpp ├── luckyitemmanager.h ├── manager.cpp ├── manager.h ├── minigamemanager.cpp ├── minigamemanager.h ├── packetmanager.cpp ├── packetmanager.h ├── questmanager.cpp ├── questmanager.h ├── rankmanager.cpp ├── rankmanager.h ├── shopmanager.cpp ├── shopmanager.h ├── userdatabase.cpp ├── userdatabase.h ├── userdatabase_shared.h ├── userdatabase_sqlite.cpp ├── userdatabase_sqlite.h ├── usermanager.cpp ├── usermanager.h ├── voxelmanager.cpp └── voxelmanager.h ├── net ├── CMakeLists.txt ├── extendedsocket.cpp ├── net.h ├── receivepacket.cpp ├── sendpacket.cpp ├── socketshared.cpp ├── tcpclient.cpp ├── tcpserver.cpp └── udpserver.cpp ├── obfuscate.h ├── packet ├── packet_metadata_data.h ├── packethelper_fulluserinfo.cpp ├── packethelper_fulluserinfo.h ├── packetin_udp.cpp └── packetin_udp.h ├── public └── net │ ├── extendedsocket.h │ ├── receivepacket.h │ ├── sendpacket.h │ ├── socketshared.h │ ├── tcpclient.h │ ├── tcpserver.h │ └── udpserver.h ├── quest ├── quest.cpp ├── quest.h ├── questevent.cpp └── questevent.h ├── room ├── gamematch.cpp ├── gamematch.h ├── room.cpp ├── room.h ├── roomsettings.cpp └── roomsettings.h ├── servercommands.h ├── serverconfig.cpp ├── serverconfig.h ├── serverinstance.cpp ├── serverinstance.h ├── test ├── CMakeLists.txt ├── net │ ├── CMakeLists.txt │ ├── net.cpp │ ├── testbasicfuncs.h │ └── testpacketsequence.h ├── testcommand.cpp ├── testevent.cpp ├── testlogger.cpp ├── testmanager.cpp └── testserver.cpp ├── thirdparty └── CMakeLists.txt └── user ├── user.cpp ├── user.h ├── userfastbuy.h ├── userinventoryitem.cpp ├── userinventoryitem.h ├── userloadout.cpp └── userloadout.h /.gitignore: -------------------------------------------------------------------------------- 1 | # msvc 2 | src/Debug 3 | src/Release 4 | src/ReleasePublic 5 | src/.vs 6 | .vs 7 | 8 | # cmake 9 | src/out 10 | src/CMakeSettings.json 11 | 12 | # srv bin files 13 | bin/*.exe 14 | bin/*.manifest 15 | bin/*.ilk 16 | bin/*.pdb 17 | bin/*.log 18 | bin/*.db3 19 | bin/Logs 20 | bin/platforms 21 | 22 | Releases -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "src/thirdparty/KeyValues"] 2 | path = src/thirdparty/KeyValues 3 | url = https://github.com/JusicP/KeyValues 4 | [submodule "src/thirdparty/SQLiteCpp"] 5 | path = src/thirdparty/SQLiteCpp 6 | url = https://github.com/SRombauts/SQLiteCpp 7 | [submodule "src/thirdparty/json"] 8 | path = src/thirdparty/json 9 | url = https://github.com/nlohmann/json 10 | [submodule "src/thirdparty/wolfssl"] 11 | path = src/thirdparty/wolfssl 12 | url = https://github.com/wolfSSL/wolfssl 13 | [submodule "src/thirdparty/zip"] 14 | path = src/thirdparty/zip 15 | url = https://github.com/kuba--/zip 16 | [submodule "src/thirdparty/rapidcsv"] 17 | path = src/thirdparty/rapidcsv 18 | url = https://github.com/d99kris/rapidcsv 19 | [submodule "src/thirdparty/doctest"] 20 | path = src/thirdparty/doctest 21 | url = https://github.com/doctest/doctest 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CSNZ Server 2 | Open-source server for the Counter-Strike Nexon: Studio game. Written in C++, supports Windows, Linux (requires tests). 3 | 4 | Don't use it for commercial purposes. 5 | 6 | # Contributing 7 | You can help the project by solving issues, detecting/fixing bugs, and various problems. 8 | 9 | # Building 10 | Currently only Windows and Linux are supported, other platforms not tested. 11 | 12 | Clone a repository: 13 | ``` 14 | git clone https://github.com/JusicP/CSNZ_Server 15 | git submodule init 16 | git submodule update --depth 1 17 | ``` 18 | 19 | ### Windows 20 | * [Visual Studio 2019 or newer](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=Community) 21 | * [CMake](https://www.cmake.org/download/) 22 | * [Qt 6.5.3 (optional)](https://www.qt.io/download-qt-installer) 23 | 24 | **Set `QTDIR` environment variable: `\Qt\6.5.3\msvc2019_64` if you want to use GUI.** 25 | 26 | Open project folder in Visual Studio and wait for CMake cache generation. 27 | Then click on Build -> Build All. 28 | 29 | ### Linux 30 | * GCC compiler 31 | * [CMake](https://www.cmake.org/download/) 32 | * [Qt 6.5.3 (optional)](https://www.qt.io/download-qt-installer) 33 | 34 | ``` 35 | cd PathToRepo/CSNZ_Server/src 36 | cmake -S . -B build 37 | cmake --build build 38 | ``` 39 | 40 | # Documentation 41 | You can find server documentation in [DOCUMENTATION.md](doc/documentation.md) file. 42 | -------------------------------------------------------------------------------- /bin/Data/ClientTable.csv: -------------------------------------------------------------------------------- 1 | rp,20135,2561,0,,Luckybox2_plusone,,,3,Luckybox2_plusone 2 | rp,2739,2739,,4100,,,,, 3 | rp,2740,2740,,4100,,,,, 4 | rp,2741,2741,,4100,,,,, 5 | rp,2742,2742,,4100,,,,, 6 | rp,20240,,,2000,classy24s1bpackage,,,,classy24s1bpackage 7 | rp,20239,,,2000,classy24s1apackage,,,,classy24s1apackage 8 | rp,20242,,,,Ritsukacouponset_240403,,,,weaponticket 9 | rp,20241,,,,zombiecouponset_240403,,,,weaponticket 10 | -------------------------------------------------------------------------------- /bin/Data/CodisData.csv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JusicP/CSNZ_Server/4859a6e73451ccbfce167b1d28deeb0457468ac3/bin/Data/CodisData.csv -------------------------------------------------------------------------------- /bin/Data/EventShop.csv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JusicP/CSNZ_Server/4859a6e73451ccbfce167b1d28deeb0457468ac3/bin/Data/EventShop.csv -------------------------------------------------------------------------------- /bin/Data/FamilyTotalWar.json: -------------------------------------------------------------------------------- 1 | { 2 | "StrategicStrongHold_ContributionLevel" : { 3 | "BonusPercentage_1" : 120, 4 | "BonusPercentage_2" : 110, 5 | "BonusPercentage_3" : 105 6 | }, 7 | 8 | "AddMaterial": 100, 9 | "MaterialWaitingTimeSecPer_AddMaterial": 60, 10 | 11 | "MaterialLimit": 1000, 12 | 13 | "WithDrawCheckPeriod": 5, 14 | "WithDrawMaterialThreshold": 60, 15 | 16 | "StrongHoldCompetitionInfoRequestDelayTime": 10, 17 | 18 | "OldSeasonList": [1,2], 19 | "CurSeason": 2, 20 | 21 | "ClanAgitEvalGradeAtLeast": 4, 22 | 23 | "RewardDetailURL": "https://forum.nexon.com/csnexon/board_view?board=5702&thread=2684549", 24 | 25 | "PrepareStartTime" : "2024-11-27 04:00:00", 26 | "PrepareEndTime" : "2024-12-04 03:00:00", 27 | "TotalWarStartTime" : "2024-12-04 04:00:00", 28 | "TotalWarEndTime" : "2024-12-24 00:05:00", 29 | "RewardStartTime" : "2024-12-24 04:00:00", 30 | "RewardEndTime" : "2025-02-19 04:00:00", 31 | 32 | "LastSeasonRewardStartTime" : "2024-12-24 04:00:00", 33 | "LastSeasonRewardEndTime" : "2025-01-22 04:00:00", 34 | 35 | "MapInfo": [ 36 | { 37 | "20240808150": { 38 | "Supplies" : { 39 | "Zone_1" : 500, 40 | "Zone_2" : 600, 41 | "Zone_3" : 700, 42 | "Hub" : 800, 43 | "Refuge" : 1000 44 | }, 45 | 46 | "EvaluationScore" : { 47 | "Zone_1" : 100, 48 | "Zone_2" : 200, 49 | "Zone_3" : 300, 50 | "Hub" : 300, 51 | "Refuge" : 300, 52 | "Strategic_FirstOccupation" : 5000, 53 | "Strategic_Maintain" : 1000 54 | }, 55 | 56 | "EvaluationGrade" : { 57 | "RequiredPoint_0" : 0, 58 | "RequiredPoint_1" : 1000, 59 | "RequiredPoint_2" : 5000, 60 | "RequiredPoint_3" : 15000, 61 | "RequiredPoint_4" : 25000, 62 | "RequiredPoint_5" : 35000 63 | }, 64 | 65 | "ContributionGrade": { 66 | "RequiredPercentage_1" : 10, 67 | "RequiredPercentage_2" : 25, 68 | "RequiredPercentage_3" : 50 69 | } 70 | } 71 | } 72 | ] 73 | } 74 | -------------------------------------------------------------------------------- /bin/Data/FamilyTotalWarMap.csv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JusicP/CSNZ_Server/4859a6e73451ccbfce167b1d28deeb0457468ac3/bin/Data/FamilyTotalWarMap.csv -------------------------------------------------------------------------------- /bin/Data/Item.csv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JusicP/CSNZ_Server/4859a6e73451ccbfce167b1d28deeb0457468ac3/bin/Data/Item.csv -------------------------------------------------------------------------------- /bin/Data/MapList.csv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JusicP/CSNZ_Server/4859a6e73451ccbfce167b1d28deeb0457468ac3/bin/Data/MapList.csv -------------------------------------------------------------------------------- /bin/Data/MatchOption.csv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JusicP/CSNZ_Server/4859a6e73451ccbfce167b1d28deeb0457468ac3/bin/Data/MatchOption.csv -------------------------------------------------------------------------------- /bin/Data/Metadata_ReinforceItemsExp.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JusicP/CSNZ_Server/4859a6e73451ccbfce167b1d28deeb0457468ac3/bin/Data/Metadata_ReinforceItemsExp.bin -------------------------------------------------------------------------------- /bin/Data/Metadata_Unk20.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JusicP/CSNZ_Server/4859a6e73451ccbfce167b1d28deeb0457468ac3/bin/Data/Metadata_Unk20.bin -------------------------------------------------------------------------------- /bin/Data/Metadata_Unk3.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JusicP/CSNZ_Server/4859a6e73451ccbfce167b1d28deeb0457468ac3/bin/Data/Metadata_Unk3.bin -------------------------------------------------------------------------------- /bin/Data/Metadata_Unk31.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JusicP/CSNZ_Server/4859a6e73451ccbfce167b1d28deeb0457468ac3/bin/Data/Metadata_Unk31.bin -------------------------------------------------------------------------------- /bin/Data/Metadata_Unk43.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JusicP/CSNZ_Server/4859a6e73451ccbfce167b1d28deeb0457468ac3/bin/Data/Metadata_Unk43.bin -------------------------------------------------------------------------------- /bin/Data/Metadata_Unk49.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JusicP/CSNZ_Server/4859a6e73451ccbfce167b1d28deeb0457468ac3/bin/Data/Metadata_Unk49.bin -------------------------------------------------------------------------------- /bin/Data/Metadata_Unk54.bin: -------------------------------------------------------------------------------- 1 | 6%  0  2 | 0   00 3 |   ! " 4 | # 5 | $ 6 | % -------------------------------------------------------------------------------- /bin/Data/Metadata_Unk55.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JusicP/CSNZ_Server/4859a6e73451ccbfce167b1d28deeb0457468ac3/bin/Data/Metadata_Unk55.bin -------------------------------------------------------------------------------- /bin/Data/Metadata_Unk8.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JusicP/CSNZ_Server/4859a6e73451ccbfce167b1d28deeb0457468ac3/bin/Data/Metadata_Unk8.bin -------------------------------------------------------------------------------- /bin/Data/MileageShop.csv: -------------------------------------------------------------------------------- 1 | ;ProductId,RN,price,begintime, endtime, Totalcount, PersonalCount,PersonalDailyCount, saleRate, SaleBeginTime, SaleEndtime, tag, ItemID1,num1,day1,ItemID2,num2,day2,ItemID3,num3,day3,ItemID4,num4,day4,ItemID5,num5,day5 2 | 24112701,2796,5000,2024-12-04 4:00,2024-12-23 23:00,0,0,5,0,0,0,64,2796,1,0,0,0,0,0,0,0,0,0,0,0,0,0 3 | 25031901,2711,500,0,0,0,0,5,0,0,0,64,2711,10,0,0,0,0,0,0,0,0,0,0,0,0,0 4 | 25031902,59,200,0,0,0,0,1,0,0,0,64,59,1,1,0,0,0,0,0,0,0,0,0,0,0,0 5 | 25031903,8623,100,0,0,0,0,1,0,0,0,64,8623,1,1,0,0,0,0,0,0,0,0,0,0,0,0 6 | 25031904,8195,200,0,0,0,0,1,0,0,0,64,8195,1,1,0,0,0,0,0,0,0,0,0,0,0,0 7 | 25031905,8196,200,0,0,0,0,1,0,0,0,64,8196,1,1,0,0,0,0,0,0,0,0,0,0,0,0 8 | 25031906,8167,100,0,0,0,0,1,0,0,0,68,8167,1,1,0,0,0,0,0,0,0,0,0,0,0,0 9 | 25031907,944,100,0,0,0,0,1,0,0,0,68,944,1,1,0,0,0,0,0,0,0,0,0,0,0,0 10 | 25031908,943,100,0,0,0,0,1,0,0,0,68,943,1,1,0,0,0,0,0,0,0,0,0,0,0,0 11 | 25031909,8084,100,0,0,0,0,1,0,0,0,68,8084,1,1,0,0,0,0,0,0,0,0,0,0,0,0 12 | 25031910,8085,100,0,0,0,0,1,0,0,0,68,8085,1,1,0,0,0,0,0,0,0,0,0,0,0,0 13 | 25031911,8107,100,0,0,0,0,1,0,0,0,68,8107,1,1,0,0,0,0,0,0,0,0,0,0,0,0 14 | 25031912,1056,100,0,0,0,0,1,0,0,0,68,1056,1,1,0,0,0,0,0,0,0,0,0,0,0,0 15 | 25031913,1055,100,0,0,0,0,1,0,0,0,68,1055,1,1,0,0,0,0,0,0,0,0,0,0,0,0 16 | 25031914,8135,100,0,0,0,0,1,0,0,0,68,8135,1,1,0,0,0,0,0,0,0,0,0,0,0,0 17 | 25031915,8134,100,0,0,0,0,1,0,0,0,68,8134,1,1,0,0,0,0,0,0,0,0,0,0,0,0 18 | 25031916,8566,1000,0,0,0,0,5,0,0,0,68,8566,1,0,0,0,0,0,0,0,0,0,0,0,0,0 19 | 25031917,8481,2000,0,0,0,0,1,0,0,0,68,8481,1,0,0,0,0,0,0,0,0,0,0,0,0,0 20 | 25031918,5250,500,0,0,0,0,0,0,0,0,1,5250,1,0,0,0,0,0,0,0,0,0,0,0,0,0 21 | 25031919,5250,5000,0,0,0,0,0,0,0,0,1,5250,10,0,0,0,0,0,0,0,0,0,0,0,0,0 22 | 25031920,65,15000,0,0,1000,1,0,0,0,0,68,65,1,0,0,0,0,0,0,0,0,0,0,0,0,0 23 | 25031921,8044,10000,0,0,0,0,0,0,0,0,1,8044,1,0,0,0,0,0,0,0,0,0,0,0,0,0 24 | 25031922,8324,9000,0,0,0,0,0,0,0,0,1,8324,1,0,0,0,0,0,0,0,0,0,0,0,0,0 25 | 25031923,8325,15000,0,0,0,0,0,0,0,0,1,8325,1,0,0,0,0,0,0,0,0,0,0,0,0,0 26 | 25031924,8326,30000,0,0,0,0,0,0,0,0,1,8326,1,0,0,0,0,0,0,0,0,0,0,0,0,0 27 | 25031925,91,5000,0,0,0,0,0,0,0,0,4,91,1,0,0,0,0,0,0,0,0,0,0,0,0,0 28 | 25031926,94,5000,0,0,0,0,0,0,0,0,4,94,1,0,0,0,0,0,0,0,0,0,0,0,0,0 29 | 25031927,455,500,0,0,0,0,0,0,0,0,4,455,1,7,0,0,0,0,0,0,0,0,0,0,0,0 30 | 25031928,455,1500,0,0,0,0,0,0,0,0,4,455,1,30,0,0,0,0,0,0,0,0,0,0,0,0 31 | -------------------------------------------------------------------------------- /bin/Data/ReinforceMaxEXP.csv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JusicP/CSNZ_Server/4859a6e73451ccbfce167b1d28deeb0457468ac3/bin/Data/ReinforceMaxEXP.csv -------------------------------------------------------------------------------- /bin/Data/ReinforceMaxLv.csv: -------------------------------------------------------------------------------- 1 | ;Id,TotalMaxLv,Damage,Accuracy,KickBack,Weight,FireRate,Ammo,9over_dmg 2 | 148,8,3,4,5,3,2,1, 3 | 197,8,5,0,5,2,2,2, 4 | 220,8,3,0,5,3,2,2, 5 | 268,8,3,4,5,3,2,1, 6 | 271,8,5,3,2,3,3,2, 7 | 304,8,2,2,5,2,3,5, 8 | 327,5,5,0,0,0,0,0, 9 | 337,9,2,1,5,4,3,3,30 10 | 341,8,5,3,3,1,3,3, 11 | 344,8,2,1,5,3,2,5, 12 | 354,8,3,4,5,3,2,1, 13 | 355,8,3,2,5,2,3,3, 14 | 363,4,0,0,0,0,4,0, 15 | 365,9,5,0,0,0,0,3,10 16 | 367,4,3,0,0,0,0,1, 17 | 370,9,4,3,4,2,3,2,30 18 | 371,8,5,3,3,1,3,3, 19 | 380,9,2,1,5,4,3,3,30 20 | 382,8,3,3,3,3,3,3, 21 | 384,9,5,0,2,2,2,5,30 22 | 385,8,2,1,5,2,3,5, 23 | 400,8,4,3,5,3,2,1, 24 | 406,8,5,3,2,3,3,2, 25 | 407,4,3,0,0,0,0,1, 26 | 414,8,3,3,5,1,1,5, 27 | 420,8,2,2,5,2,3,5, 28 | 424,8,2,2,5,3,2,5, 29 | 427,4,3,0,0,0,0,1, 30 | 428,6,3,0,0,0,0,3, 31 | 431,8,2,1,5,3,5,2, 32 | 434,8,4,3,5,3,2,1, 33 | 441,9,5,0,2,2,2,5,30 34 | 442,8,3,1,5,3,3,3, 35 | 466,5,5,0,0,0,0,0, 36 | 469,8,3,4,5,1,5,0, 37 | 483,6,3,0,0,0,3,0, 38 | 484,8,2,1,5,2,3,5, 39 | 487,5,3,0,0,0,0,2, 40 | 488,8,3,2,5,2,3,3, 41 | 493,8,2,0,5,5,1,2, 42 | 495,6,3,0,0,0,0,3, 43 | 509,8,5,3,2,5,1,2, 44 | 518,9,4,0,0,0,0,4,10 45 | 525,5,5,2,3,2,1,5, 46 | 538,4,3,0,0,0,0,1, 47 | 549,8,3,4,5,1,5,0, 48 | 564,6,3,0,0,0,0,3, 49 | 582,6,3,0,0,0,0,3, 50 | 583,8,2,0,5,5,1,2, 51 | 585,8,3,5,3,2,3,2, 52 | 588,8,2,3,5,1,2,5, 53 | 590,8,5,3,2,5,1,2, 54 | 591,8,5,0,5,2,2,2, 55 | 601,9,5,0,3,0,0,0,15 56 | 602,8,3,3,5,1,1,5, 57 | 608,8,5,2,3,5,2,1, 58 | 609,6,3,0,0,0,0,3, 59 | 677,5,3,0,0,0,0,2, 60 | 688,5,5,0,0,0,0,0, 61 | 703,6,3,0,0,0,0,3, 62 | 719,5,3,0,0,0,0,2, 63 | 727,6,3,3,0,0,0,0, 64 | 752,5,3,0,2,0,0,0, 65 | 753,9,5,0,5,5,3,0,20 66 | 761,6,3,0,0,0,0,3, 67 | 763,6,3,0,0,0,0,3, 68 | 764,5,3,0,0,0,0,2, 69 | 768,8,2,3,4,1,3,5, 70 | 771,6,3,3,0,0,0,0, 71 | 776,5,3,2,0,0,0,0, 72 | 784,5,3,0,0,0,0,2, 73 | 792,5,3,0,0,2,0,0, 74 | 796,5,3,0,0,0,0,2, 75 | 809,9,4,0,0,0,0,4,4 76 | 810,9,4,0,0,0,0,4,4 77 | 812,5,3,0,0,0,0,2, 78 | 814,6,3,0,0,0,0,3, 79 | 834,5,3,0,0,0,0,2, 80 | 841,6,3,3,0,0,0,0, 81 | 844,6,3,0,0,0,0,3, 82 | 877,9,4,0,0,0,0,4,15 83 | 891,6,3,0,0,0,0,3, 84 | 893,5,3,0,0,2,0,0, 85 | 899,5,3,0,2,0,0,0, 86 | 901,8,5,5,5,5,5,5, 87 | 902,8,5,5,5,5,5,5, 88 | 903,8,5,5,5,5,5,5, 89 | 904,8,5,5,5,5,5,5, 90 | 905,8,5,5,5,5,5,5, 91 | 906,8,5,5,5,5,5,5, 92 | 907,8,5,5,5,5,5,5, 93 | 908,8,5,5,5,5,5,5, 94 | 909,8,5,5,5,5,5,5, 95 | 910,8,5,5,5,5,5,5, 96 | 919,6,3,0,0,0,3,0, 97 | 921,5,3,0,0,0,0,2, 98 | 924,5,3,0,0,2,0,0, 99 | 935,9,4,0,0,0,0,4,4 100 | 936,9,4,0,0,0,0,4,4 101 | 937,6,3,3,0,0,0,0, 102 | 959,6,3,0,0,0,0,3, 103 | 964,5,3,0,0,2,0,0, 104 | 978,6,3,0,0,0,0,3, 105 | 983,5,3,0,0,0,0,2, 106 | 8118,5,3,0,0,0,0,2, 107 | 8119,5,3,0,0,0,0,2, 108 | 8193,5,3,0,0,2,0,0, 109 | 8219,5,3,0,0,0,0,2, 110 | 8383,5,3,2,0,0,0,0, 111 | 8221,5,3,0,2,0,0,0, 112 | 8385,5,3,0,2,0,0,0, 113 | 577,5,3,0,0,0,0,2, 114 | 842,5,0,0,0,0,2,3, 115 | 8049,8,2,4,5,2,3,2, 116 | 682,8,3,2,5,1,5,2, 117 | 683,8,5,0,3,5,3,2, 118 | 920,8,3,2,2,3,3,5, 119 | 977,8,1,0,5,5,5,2, 120 | 307,8,5,0,4,5,4,0, 121 | 8871,8,5,2,4,2,2,3, 122 | 8872,8,5,2,3,4,2,2, 123 | 8873,8,5,0,2,4,3,4, 124 | 8874,8,5,5,0,0,5,0, 125 | 8875,8,5,1,5,1,3,3, 126 | 8883,8,3,1,5,2,2,5, 127 | 8884,8,5,1,3,2,4,3, 128 | 8885,8,5,2,2,2,4,3, 129 | 8944,8,3,2,4,3,3,3, 130 | 8977,8,3,1,3,5,4,2, 131 | 9003,8,5,3,1,5,1,3, 132 | 9004,8,5,0,1,4,5,3, 133 | 9005,8,5,5,0,3,2,0, 134 | 9057,8,3,4,3,3,2,3, 135 | 9058,8,3,4,5,2,2,2, 136 | 9117,8,3,1,2,4,4,4, 137 | 9118,8,3,4,4,3,0,4, 138 | 9119,8,4,3,2,2,3,4, 139 | 9169,5,3,0,0,2,0,0, 140 | 9206,8,3,1,3,3,3,5, 141 | 9207,8,3,3,2,3,3,4, 142 | 9259,8,3,2,2,4,3,4, 143 | -------------------------------------------------------------------------------- /bin/Data/SQL/HoldBingoEvent.sql: -------------------------------------------------------------------------------- 1 | DELETE FROM UserMiniGameBingo; 2 | DELETE FROM UserMiniGameBingoSlot; 3 | DELETE FROM UserMiniGameBingoPrizeSlot; -------------------------------------------------------------------------------- /bin/Data/SQL/HoldWeaponReleaseEvent.sql: -------------------------------------------------------------------------------- 1 | DELETE FROM UserMiniGameWeaponReleaseItemProgress; 2 | DELETE FROM UserMiniGameWeaponReleaseCharacters; -------------------------------------------------------------------------------- /bin/Data/SQL/Update_2.sql: -------------------------------------------------------------------------------- 1 | ALTER TABLE UserInventory ADD COLUMN paintIDList TEXT DEFAULT ''; 2 | ALTER TABLE UserInventory ADD COLUMN lockStatus INT; 3 | ALTER TABLE UserCostumeLoadout ADD COLUMN pet INT; 4 | 5 | CREATE TABLE IF NOT EXISTS "UserAddon" ( 6 | "userID" INT NOT NULL, 7 | "itemID" INT NOT NULL, 8 | FOREIGN KEY("userID") REFERENCES "UserCharacter"("userID") ON DELETE CASCADE 9 | ); -------------------------------------------------------------------------------- /bin/Data/SQL/Update_3.sql: -------------------------------------------------------------------------------- 1 | ALTER TABLE UserCharacter ADD COLUMN nameplateID INT DEFAULT 0; 2 | ALTER TABLE UserCharacterExtended ADD COLUMN zbRespawnEffect INT DEFAULT 0; 3 | ALTER TABLE UserCharacterExtended ADD COLUMN killerMarkEffect INT DEFAULT 0; -------------------------------------------------------------------------------- /bin/Data/SQL/Update_4.sql: -------------------------------------------------------------------------------- 1 | ALTER TABLE UserCharacter ADD COLUMN chatColorID INT DEFAULT 0; -------------------------------------------------------------------------------- /bin/Data/WeaponProp.json: -------------------------------------------------------------------------------- 1 | { 2 | "weaponProp": [ 3 | ] 4 | } -------------------------------------------------------------------------------- /bin/Data/ZBCompetitive.json: -------------------------------------------------------------------------------- 1 | { 2 | "MaxCost": 3 | { 4 | "Normal": 25, 5 | "Hero":25 6 | }, 7 | "WeaponCost":[0, 1, 3, 5, 9, 15], 8 | "WeaponCostMax":[0, 2, 4, 8, 14, 20], 9 | 10 | "WeaponCooltime": [ 11 | { 12 | "Grade": 4, // 유니크 13 | "List": [ 14 | { // (포함해서 이하) 15 | "MaxZLevel": 24, 16 | "Value": 0 17 | }, 18 | { // 위 조건 초과부터 현재 조건 이하 19 | "MaxZLevel": 99999, 20 | "Value": 1 21 | } 22 | ] 23 | }, 24 | { 25 | "Grade": 5, // 초월 26 | "List": [ 27 | { 28 | "MaxZLevel": 19, 29 | "Value": 1 30 | }, 31 | { 32 | "MaxZLevel": 32, 33 | "Value": 2 34 | }, 35 | { 36 | "MaxZLevel": 99999, 37 | "Value": 3 38 | } 39 | ] 40 | }, 41 | { 42 | "Grade": 6, // 에픽 43 | "List": [ 44 | { 45 | "MaxZLevel": 99999, 46 | "Value": 4 47 | } 48 | ] 49 | } 50 | ] 51 | } -------------------------------------------------------------------------------- /bin/Data/progress_unlock.csv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JusicP/CSNZ_Server/4859a6e73451ccbfce167b1d28deeb0457468ac3/bin/Data/progress_unlock.csv -------------------------------------------------------------------------------- /bin/Data/scenariotx_common.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JusicP/CSNZ_Server/4859a6e73451ccbfce167b1d28deeb0457468ac3/bin/Data/scenariotx_common.json -------------------------------------------------------------------------------- /bin/Data/scenariotx_dedi.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JusicP/CSNZ_Server/4859a6e73451ccbfce167b1d28deeb0457468ac3/bin/Data/scenariotx_dedi.json -------------------------------------------------------------------------------- /bin/Data/voxel_list.csv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JusicP/CSNZ_Server/4859a6e73451ccbfce167b1d28deeb0457468ac3/bin/Data/voxel_list.csv -------------------------------------------------------------------------------- /bin/EventQuests.json: -------------------------------------------------------------------------------- 1 | { 2 | "Version": 1, 3 | "1": { 4 | "Active": true, 5 | "Tasks": { 6 | "1": { 7 | "Goal": 2000, 8 | "Notice": { 9 | "Goal": 10, 10 | "UserMsg": "Number of kill points %d/%d achieved with the Dual Infinity" 11 | }, 12 | "RewardID": 1111, 13 | "Conditions": { 14 | "1": { 15 | "EventType": 2, 16 | "GunID": 242, 17 | "CheckForGun": true, 18 | "GoalPoints": 1, 19 | "Bot": 1 20 | }, 21 | "2": { 22 | "EventType": 2, 23 | "GunID": 242, 24 | "CheckForGun": true, 25 | "GoalPoints": 5, 26 | "Bot": 0 27 | }, 28 | "3": { 29 | "GameModes": [8, 9, 14, 29], 30 | "EventType": 2, 31 | "VictimTeam": 1, 32 | "GunID": 242, 33 | "CheckForGun": true, 34 | "GoalPoints": 15, 35 | "Bot": 0 36 | } 37 | } 38 | }, 39 | "2": { 40 | "Goal": 2000, 41 | "Notice": { 42 | "Goal": 10, 43 | "UserMsg": "Number of kill points %d/%d achieved with the Dual Infinity Custom" 44 | }, 45 | "RewardID": 1112, 46 | "Conditions": { 47 | "1": { 48 | "EventType": 2, 49 | "GunID": 245, 50 | "CheckForGun": true, 51 | "GoalPoints": 1, 52 | "Bot": 1 53 | }, 54 | "2": { 55 | "EventType": 2, 56 | "GunID": 245, 57 | "CheckForGun": true, 58 | "GoalPoints": 5, 59 | "Bot": 0 60 | }, 61 | "3": { 62 | "GameModes": [8, 9, 14, 29], 63 | "EventType": 2, 64 | "VictimTeam": 1, 65 | "GunID": 245, 66 | "CheckForGun": true, 67 | "GoalPoints": 15, 68 | "Bot": 0 69 | } 70 | } 71 | } 72 | } 73 | } 74 | } -------------------------------------------------------------------------------- /docs/codingstyle.md: -------------------------------------------------------------------------------- 1 | # Coding style 2 | The code is written using Hungarian notation. 3 | 4 | ### Variable naming: 5 | - g_tX for global variables; 6 | - m_tX for class members; 7 | - s_tX for static variables, 8 | where "t" is type name prefix and "X" is qualifier. Qualifiers starts with a capital if type and scope present. For local scope you don't need to specify scope and type prefix 9 | Example: 10 | 11 | ``` 12 | bool g_bButtonClicked; 13 | bool g_bRunning; 14 | 15 | void Function() 16 | { 17 | bool var; 18 | ... 19 | } 20 | ``` 21 | 22 | ### Type naming: 23 | - "i" or "n": integer 24 | - "b": boolean 25 | - "sz": zero terminated string 26 | - "p": pointer 27 | - "f": float 28 | - "d": double 29 | - "dw": double word 30 | 31 | If there is no type from list you need, you can leave type empty. 32 | 33 | Example: 34 | ``` 35 | SomeStructure g_Structure; 36 | ``` 37 | 38 | For class: 39 | ``` 40 | class CName; 41 | class IName; 42 | ``` -------------------------------------------------------------------------------- /docs/diagrams/Activity - user login.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JusicP/CSNZ_Server/4859a6e73451ccbfce167b1d28deeb0457468ac3/docs/diagrams/Activity - user login.jpg -------------------------------------------------------------------------------- /docs/diagrams/Class - network.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JusicP/CSNZ_Server/4859a6e73451ccbfce167b1d28deeb0457468ac3/docs/diagrams/Class - network.jpg -------------------------------------------------------------------------------- /docs/diagrams/Communication - client connect.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JusicP/CSNZ_Server/4859a6e73451ccbfce167b1d28deeb0457468ac3/docs/diagrams/Communication - client connect.jpg -------------------------------------------------------------------------------- /docs/diagrams/Deployment - server.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JusicP/CSNZ_Server/4859a6e73451ccbfce167b1d28deeb0457468ac3/docs/diagrams/Deployment - server.jpg -------------------------------------------------------------------------------- /docs/diagrams/Interation overview - client connect.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JusicP/CSNZ_Server/4859a6e73451ccbfce167b1d28deeb0457468ac3/docs/diagrams/Interation overview - client connect.jpg -------------------------------------------------------------------------------- /docs/diagrams/Sequence - User login.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JusicP/CSNZ_Server/4859a6e73451ccbfce167b1d28deeb0457468ac3/docs/diagrams/Sequence - User login.jpg -------------------------------------------------------------------------------- /docs/diagrams/Sequence - client connect.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JusicP/CSNZ_Server/4859a6e73451ccbfce167b1d28deeb0457468ac3/docs/diagrams/Sequence - client connect.jpg -------------------------------------------------------------------------------- /docs/diagrams/Use case - net code.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JusicP/CSNZ_Server/4859a6e73451ccbfce167b1d28deeb0457468ac3/docs/diagrams/Use case - net code.jpg -------------------------------------------------------------------------------- /docs/diagrams/srv.vpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JusicP/CSNZ_Server/4859a6e73451ccbfce167b1d28deeb0457468ac3/docs/diagrams/srv.vpp -------------------------------------------------------------------------------- /docs/documentation.md: -------------------------------------------------------------------------------- 1 | # Documentation 2 | ### [Coding style](codingstyle.md) 3 | ### [Server configuration](serverconfiguration.md) 4 | ### [Glossary](glossary.md) -------------------------------------------------------------------------------- /docs/eventquests.md: -------------------------------------------------------------------------------- 1 | # EventQuests.json 2 | ### Fields 3 | ``` 4 | { 5 | "Version": , // config version (def. 0) 6 | // Quest list 7 | "": { // Quest ID 8 | "Active": , // is quest active (def. false) 9 | "Tasks": { // tasks (array) 10 | "Goal": , // number of goal points needed to finish task (def. 1) 11 | "RewardID": , // reward ID from ItemRewards.json (def. 0) 12 | "Notice": { // notice message shown on client 13 | "Goal": , // show progress message on client every X points (def. 0) 14 | "UserMsg": , // progress message (def. "%d/%d"); 15 | }, 16 | "Conditions": { // conditions needed to earn goal points (array) 17 | "": { // conditition ID 18 | "GameModes": [], // game mode conditition (array) (def. empty) 19 | "Maps": [], // maps condition (array) (def. empty) 20 | "PlayerCount": , // minimum number of players needed to finish task (def. 0) 21 | "GoalPoints": , // number of goal points that will be given to user (def. 1) 22 | "EventType": , // type of event (check QuestTaskEventType structure) (def. 0) 23 | // Variables for event type 24 | // EVENT_KILL (2): 25 | "KillerTeam": , // -1 - ignore, 1 - tr, 2 - ct (def. -1) 26 | "VictimKillType": , // -1 - ignore, 1 - headshot, 2 - knife, 16 - grenade, 32 - sentry gun (human scenario), 144 - zombie bomb, 512 - air strike (def. -1) 27 | "VictimTeam": , // -1 - ignore, 1 - tr, 2 - ct (def. -1) 28 | "Continuous": , // 1 - reset condition progress if user didn't follow them (def. 0) 29 | "GunID": , // item id of the gun (def. -1) 30 | "CheckForGun": , // check if user has gun in his inventory (def. false) 31 | "Bot": , // victim is bot, -1 - ignore, 0 - not bot, 1 - bot (def. -1) 32 | // EVENT_KILLMONSTER (10): 33 | "MonsterType": , // monster(zombie) ID 34 | } 35 | } 36 | } 37 | } 38 | } 39 | ``` 40 | def. means that if the field is undefined, the default value will be used. -------------------------------------------------------------------------------- /docs/glossary.md: -------------------------------------------------------------------------------- 1 | Note: the glossary is not complete 2 | 3 | **Server** - an application that processes client requests. 4 | 5 | **Master server** - a server that processes the actions of users such as creating/joining a game server, storing game statistics, communication between users, chatting, inventory i.e. weapons and other user items. 6 | 7 | **Client** - the one who connected to the server (master server). 8 | 9 | **Packet** - a unit of data sent over network. It consists of header and user data (payload). Header contains information about the user data length, sequence number to ensure that packets arrive in the correct sequence, magic number to identify a valid packet. 10 | 11 | **User** - a client logged in to the master server. 12 | 13 | **Login** - the procedure of client authentication using a login and password or other data. 14 | 15 | **Player** - a user who connected to the game server. 16 | 17 | **Game server (game match server)** - a server that is located on the user's side or a master server (dedicated server) at the start of a game match, which provides communication between players within the game. 18 | 19 | **Game match** - a structure that is created after the game server starts in the room and stores data of the game state (game time, some settings, game statistics for each player, which is then used to generate game results. These results affect the crediting of rewards for the game). 20 | 21 | **Room** - a game room created by a user and belonging to a specific channel in which the user is joined. It can be accessed by other users who are in the same channel. Room has a host - a user who manages the room (kicking users, changing room settings) 22 | 23 | **Channel** - the structure to which users belong. Channels can have certain restrictions on the creation of game rooms (for example, their number) or the connection of certain users to it (restrictions on the level of the user). 24 | 25 | **Channel server** - the same as the master server, but in the context of channels. -------------------------------------------------------------------------------- /docs/itembox.md: -------------------------------------------------------------------------------- 1 | # ItemBox.json 2 | ### Fields 3 | ``` 4 | { 5 | "Version": , // config version (def. 0) 6 | // Decoder list 7 | "": { // Decoder item ID 8 | "Rate": { // array of rates 9 | "": { // probability (from 0 to 100) 10 | "Grade": , // item grade 1 - default, 2 - normal, 3 - advanced, 4 - premium (def. 0) 11 | "Duration": [], // array of durations (in days) (def. empty) 12 | "Items": [], // array of items (itemID) (def. empty) 13 | } 14 | } 15 | } 16 | } 17 | ``` 18 | The sum of all rates for each decoder must be less or equal to 100. 19 | def. means that if the field is undefined, the default value will be used. -------------------------------------------------------------------------------- /docs/itemrewards.md: -------------------------------------------------------------------------------- 1 | # ItemRewards.json 2 | ### Fields 3 | ``` 4 | { 5 | "Version": , // config version (def. 0) 6 | // Reward list 7 | "": { // Reward ID 8 | "Select": , // allow user to select item (def. false) 9 | "LvlRestriction": , // level restriction (def. 0) 10 | "Points": [], // random number of point that will be given to user (array) (def. empty) 11 | "Exp": [], // the same as points (array) (def. empty) 12 | "HonorPoints": [], // the same as points (array) (def. empty) 13 | "Title": , // reward title (def. "") 14 | "Description": , // reward description (def. "") 15 | "Localized": , // if set to true, title and description fields will determine the string to use from the language files (def. false) 16 | "Items": { // array of items 17 | "": { // Item ID 18 | "Count": , // count (def. 1) 19 | "Duration": // duration (in days) (def. 0) 20 | } 21 | }, 22 | "RandomItems": { // array of random items with drop probability 23 | "": { // probability (array) 24 | "": { // Item ID 25 | "Count": , // count (def. 1) 26 | "Duration": // duration (in days) (def. 0) 27 | } 28 | } 29 | } 30 | } 31 | } 32 | ``` 33 | def. means that if the field is undefined, the default value will be used. -------------------------------------------------------------------------------- /docs/randomweaponlist.md: -------------------------------------------------------------------------------- 1 | # RandomWeaponList.json 2 | ### Fields 3 | ``` 4 | { 5 | "Version": 1, // config version (def. 0) 6 | // Random Weapon list 7 | "": { // Weapon ID 8 | "": { // mode flag. 0 = Zombie Hero, 1 = Zombie Hero (Advanced Supply Box), 2 = Zombie Evolution, 3 = Zombie Evolution (Advanced Supply Box), 4 = Zombie Classic, 5 = Zombie Classic (Advanced Supply Box) (def. 0) 9 | "DropRate": , // rate of appearance. official server has these values: 111, 222, 333, 444, 555. the higher the number, the more likely the weapon will be chosen (def. 0) 10 | "EnhanceProbability": // probability of the weapon being maximum enhanced, ranges from 0 to 100 (def. 0) 11 | } 12 | } 13 | } 14 | ``` 15 | def. means that if the field is undefined, the default value will be used. -------------------------------------------------------------------------------- /docs/serverconfiguration.md: -------------------------------------------------------------------------------- 1 | # Server configuration 2 | 3 | [ServerConfig.json](serverconfig.md) 4 | [ItemRewards.json](itemrewards.md) 5 | [ItemBox.json](itembox.md) 6 | [EventQuests.json](eventquests.md) 7 | [Shop.json](shop.md) 8 | -------------------------------------------------------------------------------- /docs/shop.md: -------------------------------------------------------------------------------- 1 | # Shop.json 2 | ### Fields 3 | ``` 4 | { 5 | "Version": , // config version (def. 0) 6 | "Recommended": { // recommended items(itemID) (array) 7 | "": [ // page ID 8 | // product ID 9 | ] 10 | }, 11 | "Popular": [], // popular items(itemID) (array) 12 | // Shop list 13 | "Products": { // products (array) 14 | "": { // itemID 15 | "IsPoints": , // product is costs points (def. 0) 16 | "SubProducts": { // array of subproducts (def. empty) 17 | "": { // sub product ID 18 | "Count": , // item count (def. 1) 19 | "Duration": , // item duration (def. 0) 20 | "Price": , // item price (points or cash) (def. 0) 21 | "AdditionalPoints": , // number of points that will be given after purchase (def. 0) 22 | "AdditionalClanPoints": , // number of clan points that will be given after purchase (def. 0) 23 | "AdType": // advertisement type (def. 0) 24 | } 25 | } 26 | } 27 | } 28 | } 29 | ``` 30 | def. means that if the field is undefined, the default value will be used. -------------------------------------------------------------------------------- /docs/weaponpaints.md: -------------------------------------------------------------------------------- 1 | # WeaponPaints.json 2 | ### Fields 3 | ``` 4 | { 5 | "Version": , // config version (def. 0) 6 | // Weapon Paints list 7 | "": { // Weapon ID 8 | "Paints": [] // paint IDs (array) (def. empty) 9 | } 10 | } 11 | ``` 12 | def. means that if the field is undefined, the default value will be used. -------------------------------------------------------------------------------- /docs/zombiewarweaponlist.md: -------------------------------------------------------------------------------- 1 | # ZombieWarWeaponList.json 2 | ### Fields 3 | ``` 4 | { 5 | "Version": , // config version (def. 0) 6 | // Zombie War Weapon list 7 | "Weapons": [] // weapon IDs (array) (def. empty) 8 | } 9 | ``` 10 | def. means that if the field is undefined, the default value will be used. -------------------------------------------------------------------------------- /src/channel/channel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "room/room.h" 4 | 5 | class CChannelServer; 6 | 7 | class CChannel 8 | { 9 | public: 10 | CChannel(CChannelServer* server, int id, const std::string& channelName, int maxPlayers, const std::string& loginMsg); 11 | ~CChannel(); 12 | 13 | void Shutdown(); 14 | 15 | bool UserJoin(IUser* user, bool unhide = false); 16 | void UserLeft(IUser* user, bool hide = false); 17 | void SendFullUpdateRoomList(); 18 | void SendFullUpdateRoomList(IUser* user); 19 | void SendUpdateRoomList(IRoom* room); 20 | void SendAddRoomToRoomList(IRoom* room); 21 | void SendRemoveFromRoomList(int roomId); 22 | void SendUserMessageToAllUser(int type, int senderUserID, const std::string& senderName, const std::string& msg); 23 | void UpdateUserInfo(IUser* user, const CUserCharacter& character); 24 | IRoom* CreateRoom(IUser* host, CRoomSettings* settings); 25 | IRoom* GetRoomById(int id); 26 | IUser* GetUserById(int userID); 27 | void RemoveRoom(IRoom* room); 28 | bool RemoveUser(IUser* user); 29 | 30 | int GetID(); 31 | std::string GetName(); 32 | std::vector GetRooms(); 33 | std::vector GetUsers(); 34 | std::vector GetOutsideUsers(); 35 | 36 | CChannelServer* GetParentChannelServer(); 37 | 38 | private: 39 | CChannelServer* m_pParentChannelServer; 40 | 41 | int m_nID; 42 | int m_nNextRoomID; 43 | int m_nMaxPlayers; 44 | std::string m_szName; 45 | std::string m_LoginMsg; 46 | 47 | std::vector m_Rooms; 48 | std::vector m_Users; 49 | }; -------------------------------------------------------------------------------- /src/channel/channelserver.cpp: -------------------------------------------------------------------------------- 1 | #include "channelserver.h" 2 | #include "common/utils.h" 3 | #include "serverconfig.h" 4 | 5 | using namespace std; 6 | 7 | CChannelServer::CChannelServer(string serverName, int serverIndex, int totalServers, int numOfChannels) 8 | { 9 | m_Name = FormatServerName(serverName, serverIndex, totalServers); 10 | m_nIndex = serverIndex; 11 | m_nNextChannelID = 1; 12 | 13 | for (m_nIndex = 0; m_nIndex < numOfChannels; m_nIndex++) 14 | { 15 | int newChannelIndex = m_nNextChannelID; 16 | string newChannelName = FormatChannelName(serverName, serverIndex, newChannelIndex); 17 | m_Channels.push_back(new CChannel(this, newChannelIndex, newChannelName, g_pServerConfig->maxPlayers, "")); 18 | m_nNextChannelID++; 19 | } 20 | } 21 | 22 | CChannelServer::~CChannelServer() 23 | { 24 | for (auto channel : m_Channels) 25 | { 26 | delete channel; 27 | } 28 | } 29 | 30 | string CChannelServer::FormatServerName(string serverName, int serverIndex, int totalServers) 31 | { 32 | /* 33 | //иновационный подход 34 | //(почему-то std::operator+ для std::string не перегружен для работы с int, 35 | //будем делать с СИ хуйней пока что): 36 | 37 | string temp = ""; 38 | char formatted[128]; 39 | sprintf(formatted, "%s [%i / %i]", serverName.c_str(), serverIndex, totalServers); 40 | temp += formatted; 41 | return temp; 42 | */ 43 | 44 | string name(va("%s [%i / %i]", serverName.c_str(), serverIndex, totalServers)); 45 | return name; 46 | } 47 | 48 | string CChannelServer::FormatChannelName(string serverName, int serverIndex, int channedlIndex) 49 | { 50 | /* 51 | //иновационный подход 52 | //(почему-то std::operator+ для std::string не перегружен для работы с int, 53 | //будем делать с СИ хуйней пока что): 54 | 55 | string temp = ""; 56 | char formatted[128]; 57 | sprintf(formatted, "%s %i-%i", serverName.c_str(), serverIndex, channedlIndex); 58 | temp += formatted; 59 | return temp; 60 | */ 61 | 62 | string name(va("%s %i-%i", serverName.c_str(), serverIndex, channedlIndex)); 63 | return name; 64 | } 65 | 66 | CChannel* CChannelServer::GetChannelByIndex(int index) 67 | { 68 | for (auto channel : m_Channels) 69 | { 70 | if (channel->GetID() == index) 71 | return channel; 72 | } 73 | 74 | return NULL; 75 | } 76 | 77 | std::vector CChannelServer::GetChannels() 78 | { 79 | return m_Channels; 80 | } 81 | 82 | std::string CChannelServer::GetName() 83 | { 84 | return m_Name; 85 | } 86 | 87 | int CChannelServer::GetID() 88 | { 89 | return m_nIndex; 90 | } -------------------------------------------------------------------------------- /src/channel/channelserver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "channel.h" 4 | 5 | class CChannelServer 6 | { 7 | public: 8 | CChannelServer(std::string serverName, int serverIndex, int totalServers, int numOfChannels); 9 | ~CChannelServer(); 10 | 11 | CChannel* GetChannelByIndex(int index); 12 | std::vector GetChannels(); 13 | std::string GetName(); 14 | int GetID(); 15 | 16 | private: 17 | std::string FormatServerName(std::string serverName, int serverIndex, int totalServers); 18 | std::string FormatChannelName(std::string serverName, int serverIndex, int channelNumber); 19 | 20 | int m_nIndex; 21 | int m_nNextChannelID; 22 | std::vector m_Channels; 23 | std::string m_Name; 24 | }; -------------------------------------------------------------------------------- /src/command.cpp: -------------------------------------------------------------------------------- 1 | #include "command.h" 2 | #include "common/utils.h" 3 | #include "common/logger.h" 4 | 5 | using namespace std; 6 | 7 | CCommandList& CCommandList::GetInstance() 8 | { 9 | static CCommandList cmdList; 10 | return cmdList; 11 | } 12 | 13 | /** 14 | * Gets all command names 15 | * @return std::string vector of command names 16 | */ 17 | vector CCommandList::GetCommandList() 18 | { 19 | vector cmdlist; 20 | for (auto cmd : m_Commands) 21 | { 22 | cmdlist.push_back(cmd->GetName()); 23 | } 24 | 25 | return cmdlist; 26 | } 27 | 28 | /** 29 | * Adds command to command list 30 | * @param cmd Pointer to command object 31 | */ 32 | void CCommandList::AddCommand(CCommand* cmd) 33 | { 34 | if (GetCommand(cmd->GetName())) 35 | { 36 | Logger().Warn("CCommandList::AddCommand: command %s duplicate!\n", cmd->GetName().c_str()); 37 | return; 38 | } 39 | 40 | m_Commands.push_back(cmd); 41 | } 42 | 43 | /** 44 | * Removes command from command list 45 | * @param cmd Pointer to command object 46 | */ 47 | void CCommandList::RemoveCommand(CCommand* cmd) 48 | { 49 | m_Commands.erase(remove(begin(m_Commands), end(m_Commands), cmd), end(m_Commands)); 50 | } 51 | 52 | /** 53 | * Gets command object by its name 54 | * @param name Command name 55 | * @return Pointer to command object, NULL if not found 56 | */ 57 | CCommand* CCommandList::GetCommand(const std::string& name) 58 | { 59 | for (auto cmd : m_Commands) 60 | { 61 | if (cmd->GetName() == name) 62 | { 63 | return cmd; 64 | } 65 | } 66 | 67 | return NULL; 68 | } 69 | 70 | /** 71 | * Constructor. Adds command to command list 72 | * @param name Command name 73 | * @param desc Command description 74 | * @param usage Command usage (arguments) 75 | * @param func Command function 76 | */ 77 | CCommand::CCommand(const std::string& name, const std::string& desc, const std::string& usage, const function&)>& func) 78 | { 79 | m_Name = name; 80 | m_Description = desc; 81 | m_Usage = usage; 82 | m_Func = func; 83 | 84 | CCommandList::GetInstance().AddCommand(this); 85 | } 86 | 87 | /** 88 | * Destructor. Removes command from command list 89 | */ 90 | CCommand::~CCommand() 91 | { 92 | CCommandList::GetInstance().RemoveCommand(this); 93 | } 94 | 95 | string CCommand::GetName() 96 | { 97 | return m_Name; 98 | } 99 | 100 | string CCommand::GetDescription() 101 | { 102 | return m_Description; 103 | } 104 | 105 | /** 106 | * Gets command usage, its arguments 107 | * @return Usage std::string 108 | */ 109 | string CCommand::GetUsage() 110 | { 111 | return m_Usage; 112 | } 113 | 114 | /** 115 | * Executes command function with given arguments 116 | * @param args std::string vector of command arguments 117 | */ 118 | void CCommand::Exec(const vector& args) 119 | { 120 | m_Func(this, args); 121 | } -------------------------------------------------------------------------------- /src/command.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | /** 8 | * Class that represents command. Contains a name and function that will be executed by calling the Exec() method. 9 | * When creating a command object, it's added to list of commands and you can find it by its name (CCommandList::GetInstance().GetCommand(...)). 10 | */ 11 | class CCommand 12 | { 13 | public: 14 | CCommand(const std::string& name, const std::string& desc, const std::string& usage, const std::function&)>& func); 15 | ~CCommand(); 16 | 17 | std::string GetName(); 18 | std::string GetDescription(); 19 | std::string GetUsage(); 20 | 21 | void Exec(const std::vector& args); 22 | 23 | private: 24 | std::string m_Name; 25 | std::string m_Description; 26 | std::string m_Usage; 27 | std::function&)> m_Func; 28 | }; 29 | 30 | /** 31 | * Class for managing commands (add, remove, get) 32 | */ 33 | class CCommandList 34 | { 35 | private: 36 | CCommandList() = default; 37 | CCommandList(const CCommandList&) = delete; 38 | CCommandList(CCommandList&&) = delete; 39 | CCommandList& operator=(const CCommandList&) = delete; 40 | CCommandList& operator=(CCommandList&&) = delete; 41 | 42 | public: 43 | static CCommandList& GetInstance(); 44 | 45 | std::vector GetCommandList(); 46 | void AddCommand(CCommand* cmd); 47 | void RemoveCommand(CCommand* cmd); 48 | CCommand* GetCommand(const std::string& name); 49 | 50 | private: 51 | std::vector m_Commands; 52 | }; 53 | 54 | /** 55 | * Singleton 56 | */ 57 | static CCommandList& CmdList() 58 | { 59 | return CCommandList::GetInstance(); 60 | } 61 | -------------------------------------------------------------------------------- /src/common/buffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include // buffers 3 | #include // strings, byteStr() 4 | #include 5 | 6 | class Buffer { 7 | public: 8 | Buffer(); 9 | Buffer(const std::vector&); 10 | 11 | void setBuffer(std::vector&); 12 | const std::vector& getBuffer() const; 13 | void clear(); 14 | 15 | std::string byteStr(bool LE = true) const; 16 | 17 | /************************** Writing ***************************/ 18 | 19 | template inline void writeBytes(const T& val, bool LE = true); 20 | unsigned long long getWriteOffset() const; 21 | void setWriteOffset(unsigned long long newOffset); 22 | void setOverride(bool override); 23 | 24 | void writeBool(bool); 25 | void writeStr(const std::string&); 26 | void writeWStr(const std::wstring& str); 27 | void writeInt8(char); 28 | void writeUInt8(unsigned char); 29 | void writeArray(const std::vector&); 30 | void writeData(void*, int); 31 | 32 | void writeInt16_LE(short); 33 | void writeInt16_BE(short); 34 | void writeUInt16_LE(unsigned short); 35 | void writeUInt16_BE(unsigned short); 36 | 37 | void writeInt32_LE(int); 38 | void writeInt32_BE(int); 39 | void writeUInt32_LE(unsigned int); 40 | void writeUInt32_BE(unsigned int); 41 | 42 | void writeInt64_LE(long long); 43 | void writeInt64_BE(long long); 44 | void writeUInt64_LE(unsigned long long); 45 | void writeUInt64_BE(unsigned long long); 46 | 47 | void writeFloat_LE(float); 48 | void writeFloat_BE(float); 49 | void writeDouble_LE(double); 50 | void writeDouble_BE(double); 51 | 52 | /************************** Reading ***************************/ 53 | 54 | void setReadOffset(unsigned long long); 55 | unsigned long long getReadOffset() const; 56 | template inline T readBytes(bool LE = true); 57 | 58 | bool readBool(); 59 | std::string readStr(unsigned long long len); 60 | std::string readStr(); 61 | std::vector readArr(int size); 62 | char readInt8(); 63 | unsigned char readUInt8(); 64 | 65 | short readInt16_LE(); 66 | short readInt16_BE(); 67 | unsigned short readUInt16_LE(); 68 | unsigned short readUInt16_BE(); 69 | 70 | int readInt32_LE(); 71 | int readInt32_BE(); 72 | unsigned int readUInt32_LE(); 73 | unsigned int readUInt32_BE(); 74 | 75 | long long readInt64_LE(); 76 | long long readInt64_BE(); 77 | unsigned long long readUInt64_LE(); 78 | unsigned long long readUInt64_BE(); 79 | 80 | float readFloat_LE(); 81 | float readFloat_BE(); 82 | double readDouble_LE(); 83 | double readDouble_BE(); 84 | 85 | ~Buffer(); 86 | private: 87 | std::vector buffer; 88 | unsigned long long readOffset; 89 | unsigned long long writeOffset; 90 | bool overrideBuf; 91 | }; 92 | -------------------------------------------------------------------------------- /src/common/buildnum.cpp: -------------------------------------------------------------------------------- 1 | #ifdef WIN32 2 | #include 3 | #endif 4 | #include 5 | 6 | const char* pdate = __DATE__; 7 | const char* ptime = __TIME__; 8 | 9 | const char* mon[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; 10 | const char mond[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; 11 | 12 | char* build_number(void) 13 | { 14 | int m = 0; 15 | int d = 0; 16 | int y = 0; 17 | static char result[32]; 18 | static int b = 0; 19 | 20 | if (b) 21 | return result; 22 | 23 | for (m = 0; m < 11; m++) 24 | { 25 | #ifdef WIN32 26 | if (!_strnicmp(pdate, mon[m], 3)) 27 | #else 28 | if (!strncasecmp(pdate, mon[m], 3)) 29 | #endif 30 | break; 31 | 32 | d += mond[m]; 33 | } 34 | 35 | d += atoi(&pdate[4]) - 4; 36 | y = atoi(&pdate[7]) - 1900; 37 | b = d + (int)((y - 1) * 365.25); 38 | 39 | if (!(y % 4) && m > 1) 40 | b++; 41 | 42 | b -= 43205; 43 | sprintf(result, "%d", b + 1); 44 | return result; 45 | } -------------------------------------------------------------------------------- /src/common/buildnum.h: -------------------------------------------------------------------------------- 1 | char* build_number(void); 2 | -------------------------------------------------------------------------------- /src/common/net/netdefs.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define MAX_SEQUENCE 255 4 | 5 | #define PACKET_MAX_SIZE 0x10000 6 | #define PACKET_HEADER_SIZE 4 // without packet ID 7 | 8 | #define TCP_PACKET_SIGNATURE 'U' 9 | 10 | // not sure about them 11 | #define UDP_HOLEPUNCH_PACKET_SIGNATURE_1 'W' 12 | #define UDP_HOLEPUNCH_PACKET_SIGNATURE_2 'X' 13 | #define UDP_HOLEPUNCH_PACKET_SIGNATURE_3 '`' 14 | 15 | #define TCP_CONNECTED_MESSAGE "~SERVERCONNECTED\n" -------------------------------------------------------------------------------- /src/common/thread.cpp: -------------------------------------------------------------------------------- 1 | #include "thread.h" 2 | 3 | ThreadId GetCurrentThreadID() 4 | { 5 | #ifdef WIN32 6 | return GetCurrentThreadId(); 7 | #else 8 | return pthread_self(); 9 | #endif 10 | } 11 | 12 | CThread::CThread(const Handler& function, void* data) 13 | { 14 | m_Object = function; 15 | m_pData = data; 16 | #ifdef WIN32 17 | m_hHandle = 0; 18 | #endif 19 | m_ID = 0; 20 | } 21 | 22 | CThread::~CThread() 23 | { 24 | #ifdef WIN32 25 | CloseHandle(m_hHandle); 26 | #endif 27 | } 28 | 29 | // just start thread 30 | bool CThread::Start() 31 | { 32 | if (IsAlive()) 33 | { 34 | return false; 35 | } 36 | 37 | #ifdef WIN32 38 | m_hHandle = CreateThread(0, 0, reinterpret_cast(m_Object), m_pData, 0, &m_ID); 39 | if (m_hHandle == 0) 40 | { 41 | return false; 42 | } 43 | #else 44 | int result = pthread_create(&m_ID, NULL, m_Object, m_pData); 45 | if (result != 0) 46 | { 47 | return false; 48 | } 49 | #endif 50 | 51 | return true; 52 | } 53 | 54 | // pauses current thread execution until other thread is finish 55 | void CThread::Join() 56 | { 57 | #ifdef WIN32 58 | if (!m_hHandle) 59 | #else 60 | if (!m_ID) 61 | #endif 62 | return; 63 | 64 | if (IsCurrentThreadSame()) 65 | return; 66 | 67 | #ifdef WIN32 68 | DWORD dwResult = WaitForSingleObject(m_hHandle, INFINITE); 69 | if (dwResult == WAIT_FAILED) 70 | printf("CThread::Join: dwResult == WAIT_FAILED\n"); 71 | #else 72 | if (pthread_join(m_ID, NULL) != 0) 73 | printf("CThread::Join: pthread_join != 0\n"); 74 | #endif 75 | } 76 | 77 | // terminates thread (very unsafe if you don't know what you're doing) 78 | void CThread::Terminate() 79 | { 80 | #ifdef WIN32 81 | TerminateThread(m_hHandle, 0); 82 | CloseHandle(m_hHandle); 83 | m_hHandle = 0; 84 | #else 85 | pthread_kill(m_ID, SIGKILL); 86 | #endif 87 | m_ID = 0; 88 | } 89 | 90 | // checks if thread is alive (created and not exited) 91 | bool CThread::IsAlive() 92 | { 93 | #ifdef WIN32 94 | DWORD exitCode; 95 | return (m_hHandle && GetExitCodeThread(m_hHandle, &exitCode) && exitCode == STILL_ACTIVE); 96 | #else 97 | return m_ID; 98 | #endif 99 | } 100 | 101 | bool CThread::IsCurrentThreadSame() 102 | { 103 | ThreadId id = GetCurrentThreadID(); 104 | #ifdef WIN32 105 | return id == m_ID; 106 | #else 107 | return pthread_equal(id, m_ID); 108 | #endif 109 | } -------------------------------------------------------------------------------- /src/common/thread.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #ifdef WIN32 6 | #include 7 | #else 8 | #include 9 | #endif 10 | 11 | #ifdef WIN32 12 | typedef DWORD ThreadId; 13 | #else 14 | typedef pthread_t ThreadId; 15 | #endif 16 | 17 | class CObjectSync 18 | { 19 | public: 20 | CObjectSync() 21 | { 22 | #ifdef _WIN32 23 | m_hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); 24 | if (m_hEvent == NULL) 25 | printf("CObjectSync: Failed to create event\n"); 26 | #else 27 | m_bSignalled = false; 28 | pthread_mutex_init(&m_Mutex, NULL); 29 | pthread_cond_init(&m_Cond, NULL); 30 | #endif 31 | } 32 | ~CObjectSync() 33 | { 34 | #ifdef _WIN32 35 | CloseHandle(m_hEvent); 36 | #else 37 | pthread_mutex_destroy(&m_Mutex); 38 | pthread_cond_destroy(&m_Cond); 39 | #endif 40 | } 41 | 42 | void WaitForSignal() 43 | { 44 | #ifdef _WIN32 45 | DWORD dwEvent = WaitForSingleObject(m_hEvent, INFINITE); 46 | switch (dwEvent) 47 | { 48 | case WAIT_ABANDONED: 49 | printf("CObjectSync: WAIT_ABANDONED: %d\n", GetLastError()); 50 | break; 51 | case WAIT_OBJECT_0: 52 | break; 53 | case WAIT_TIMEOUT: 54 | printf("CObjectSync: WAIT_TIMEOUT: %d\n", GetLastError()); 55 | break; 56 | case WAIT_FAILED: 57 | printf("CObjectSync: WAIT_FAILED: %d\n", GetLastError()); 58 | break; 59 | } 60 | #else 61 | pthread_mutex_lock(&m_Mutex); 62 | while (!m_bSignalled) 63 | { 64 | pthread_cond_wait(&m_Cond, &m_Mutex); 65 | } 66 | m_bSignalled = false; 67 | pthread_mutex_unlock(&m_Mutex); 68 | #endif 69 | } 70 | 71 | void Signal() 72 | { 73 | #ifdef _WIN32 74 | SetEvent(m_hEvent); 75 | #else 76 | pthread_mutex_lock(&m_Mutex); 77 | m_bSignalled = true; 78 | pthread_mutex_unlock(&m_Mutex); 79 | pthread_cond_signal(&m_Cond); 80 | #endif 81 | } 82 | 83 | private: 84 | #ifdef _WIN32 85 | HANDLE m_hEvent; 86 | #else 87 | bool m_bSignalled; 88 | pthread_mutex_t m_Mutex; 89 | pthread_cond_t m_Cond; 90 | #endif 91 | }; 92 | 93 | class CCriticalSection 94 | { 95 | public: 96 | CCriticalSection() 97 | { 98 | #ifdef _WIN32 99 | InitializeCriticalSection(&m_CriticalSection); 100 | #else 101 | pthread_mutex_init(&m_Mutex, NULL); 102 | #endif 103 | } 104 | 105 | ~CCriticalSection() 106 | { 107 | #ifdef _WIN32 108 | DeleteCriticalSection(&m_CriticalSection); 109 | #else 110 | pthread_mutex_destroy(&m_Mutex); 111 | #endif 112 | } 113 | 114 | void Enter() 115 | { 116 | #ifdef _WIN32 117 | EnterCriticalSection(&m_CriticalSection); 118 | #else 119 | pthread_mutex_lock(&m_Mutex); 120 | #endif 121 | } 122 | 123 | int TryEnter() 124 | { 125 | #ifdef _WIN32 126 | return TryEnterCriticalSection(&m_CriticalSection); 127 | #else 128 | return pthread_mutex_trylock(&m_Mutex); 129 | #endif 130 | } 131 | 132 | void Leave() 133 | { 134 | #ifdef _WIN32 135 | LeaveCriticalSection(&m_CriticalSection); 136 | #else 137 | pthread_mutex_unlock(&m_Mutex); 138 | #endif 139 | } 140 | 141 | private: 142 | #ifdef _WIN32 143 | CRITICAL_SECTION m_CriticalSection; 144 | #else 145 | pthread_mutex_t m_Mutex; 146 | #endif 147 | }; 148 | 149 | typedef void* (*Handler)(void*); 150 | 151 | ThreadId GetCurrentThreadID(); 152 | 153 | // Win32/POSIX thread class 154 | class CThread 155 | { 156 | public: 157 | CThread(const Handler& function, void* data = NULL); 158 | ~CThread(); 159 | 160 | bool Start(); 161 | void Join(); 162 | void Terminate(); 163 | bool IsAlive(); 164 | bool IsCurrentThreadSame(); 165 | 166 | // threads are non-copyable 167 | CThread(const CThread&) = delete; 168 | CThread& operator=(const CThread&) = delete; 169 | 170 | private: 171 | Handler m_Object; 172 | #ifdef WIN32 173 | HANDLE m_hHandle; 174 | #endif 175 | ThreadId m_ID; 176 | void* m_pData; 177 | }; -------------------------------------------------------------------------------- /src/common/utils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | uint32_t ip_string_to_int(const std::string& in, bool* const success = nullptr); 8 | std::string ip_to_string(uint32_t in, bool* const success = nullptr); 9 | bool isNumber(const std::string& str); 10 | bool yesOrNo(float probabilityOfYes); 11 | const char* FormatSeconds(int seconds); 12 | char* va(const char* format, ...); 13 | const char* WSAGetLastErrorString(); 14 | std::vector deserialize_array_str(std::string const& csv); 15 | std::vector deserialize_array_int(std::string const& csv); 16 | std::vector deserialize_array_uchar(std::string const& csv); 17 | std::string serialize_array_str(const std::vector& arr); 18 | std::string serialize_array_int(const std::vector& arr); 19 | std::string serialize_array_uchar(const std::vector& arr); 20 | size_t findCaseInsensitive(std::string data, std::string toSearch, size_t pos = 0); 21 | size_t findCaseInsensitive(std::string data, const std::vector& toSearch, size_t pos = 0); 22 | std::vector ParseArguments(const std::string& str); 23 | void SleepMS(unsigned int ms); 24 | int GetNetworkError(); 25 | 26 | class Randomer 27 | { 28 | private: 29 | std::mt19937 gen; 30 | std::uniform_int_distribution dis; 31 | public: 32 | inline Randomer(size_t max) : dis(0, max), gen(std::random_device()()) {} 33 | inline Randomer(size_t max, unsigned int seed) : dis(0, max), gen(seed) {} 34 | inline size_t operator()() { return dis(gen); } 35 | // if you want predictable numbers 36 | inline void SetSeed(unsigned int seed) { gen.seed(seed); } 37 | }; -------------------------------------------------------------------------------- /src/crashdump.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JusicP/CSNZ_Server/4859a6e73451ccbfce167b1d28deeb0457468ac3/src/crashdump.cpp -------------------------------------------------------------------------------- /src/crashdump.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Windows.h" 4 | 5 | #ifdef _WIN32 6 | LONG __stdcall ExceptionFilter(EXCEPTION_POINTERS* pep); 7 | #endif 8 | -------------------------------------------------------------------------------- /src/csvtable.cpp: -------------------------------------------------------------------------------- 1 | #include "csvtable.h" 2 | 3 | using namespace std; 4 | -------------------------------------------------------------------------------- /src/csvtable.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "rapidcsv.h" 4 | 5 | class CCSVTable : public rapidcsv::Document 6 | { 7 | public: 8 | CCSVTable(const std::string& pPath, 9 | const rapidcsv::LabelParams& pLabelParams = rapidcsv::LabelParams(), 10 | const rapidcsv::SeparatorParams& pSeparatorParams = rapidcsv::SeparatorParams(), 11 | const rapidcsv::ConverterParams& pConverterParams = rapidcsv::ConverterParams(), 12 | const rapidcsv::LineReaderParams& pLineReaderParams = rapidcsv::LineReaderParams(), bool ignoreFirstLine = false) 13 | { 14 | m_bLoadFailed = false; 15 | 16 | std::ifstream stream; 17 | stream.open(pPath, std::ios::binary); 18 | if (!stream.is_open()) 19 | { 20 | m_bLoadFailed = true; 21 | } 22 | 23 | // read "commentary" header divided with semicolon (aka. the first line on Item.csv) 24 | if (ignoreFirstLine) 25 | { 26 | std::stringstream sstream; 27 | if (stream.is_open()) 28 | { 29 | std::vector vec(std::istreambuf_iterator{stream}, {}); 30 | std::vector::iterator it; 31 | if ((it = std::find(vec.begin(), vec.end(), '\n')) != vec.end()) 32 | { 33 | vec.erase(vec.begin(), vec.begin() + (it - vec.begin()) + 1); 34 | } 35 | 36 | std::copy(vec.begin(), vec.end(), std::ostream_iterator(sstream)); 37 | } 38 | 39 | Load(sstream, pLabelParams, pSeparatorParams, pConverterParams, pLineReaderParams); 40 | } 41 | else 42 | { 43 | Load(pPath, pLabelParams, pSeparatorParams, pConverterParams, pLineReaderParams); 44 | } 45 | } 46 | 47 | bool IsRowValueExists(const std::string& columnName, const std::string& rowValue) 48 | { 49 | std::vector column = GetColumn(columnName); 50 | 51 | return (std::find(column.begin(), column.end(), rowValue) != column.end()); 52 | } 53 | 54 | bool IsLoadFailed() 55 | { 56 | return m_bLoadFailed; 57 | } 58 | 59 | private: 60 | bool m_bLoadFailed; 61 | }; 62 | -------------------------------------------------------------------------------- /src/gui/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.20) 2 | #set(PROJECTNAME "CSO Server GUI") 3 | 4 | project(gui CXX) 5 | 6 | # required by QT 7 | set(CMAKE_AUTOMOC ON) 8 | set(CMAKE_AUTOUIC ON) 9 | set(CMAKE_AUTORCC ON) 10 | 11 | find_package(Qt6 REQUIRED COMPONENTS Widgets) 12 | 13 | add_library(gui STATIC) 14 | 15 | target_link_libraries(gui Qt6::Widgets) 16 | 17 | target_sources(gui PRIVATE "gui.cpp") 18 | target_sources(gui PRIVATE "mainwindow.ui") 19 | target_sources(gui PRIVATE "mainwindow.cpp") 20 | target_sources(gui PRIVATE "maintab.cpp") 21 | target_sources(gui PRIVATE "maintab.ui") 22 | target_sources(gui PRIVATE "consoletab.cpp") 23 | target_sources(gui PRIVATE "consoletab.ui") 24 | target_sources(gui PRIVATE "sessiontab.cpp") 25 | target_sources(gui PRIVATE "sessiontab.ui") 26 | target_sources(gui PRIVATE "roomlisttab.cpp") 27 | target_sources(gui PRIVATE "roomlisttab.ui") 28 | target_sources(gui PRIVATE "noticedialog.cpp") 29 | target_sources(gui PRIVATE "noticedialog.ui") 30 | target_sources(gui PRIVATE "selectuserdialog.cpp") 31 | target_sources(gui PRIVATE "selectuserdialog.ui") 32 | target_sources(gui PRIVATE "usercharacterdialog.cpp") 33 | target_sources(gui PRIVATE "usercharacterdialog.ui") 34 | target_sources(gui PRIVATE "userbanlistdialog.cpp") 35 | target_sources(gui PRIVATE "userbanlistdialog.ui") 36 | target_sources(gui PRIVATE "hwidbanlistdialog.cpp") 37 | target_sources(gui PRIVATE "hwidbanlistdialog.ui") 38 | target_sources(gui PRIVATE "ipbanlistdialog.cpp") 39 | target_sources(gui PRIVATE "ipbanlistdialog.ui") 40 | target_sources(gui PRIVATE "bandialog.cpp") 41 | target_sources(gui PRIVATE "bandialog.ui") 42 | 43 | target_sources(gui PRIVATE "../common/utils.cpp") 44 | 45 | target_include_directories(gui PUBLIC 46 | "../" 47 | ) -------------------------------------------------------------------------------- /src/gui/bandialog.cpp: -------------------------------------------------------------------------------- 1 | #include "bandialog.h" 2 | #include 3 | #include 4 | 5 | #include "gui.h" 6 | #include "interface/ievent.h" 7 | #include "interface/iuserdatabase.h" 8 | #include "interface/iserverinstance.h" 9 | 10 | CBanDialog::CBanDialog(QWidget* parent, const Session& session) : QDialog(parent) 11 | { 12 | m_pUI = new Ui::BanDialog(); 13 | m_pUI->setupUi(this); 14 | 15 | m_Session = session; 16 | 17 | setWindowFlags(windowFlags() | Qt::MSWindowsFixedSizeDialogHint); 18 | 19 | m_pUI->ExpiryDateEntry->setMinimumDateTime(QDateTime::currentDateTime()); 20 | 21 | m_pUI->BanClientID->setText(m_pUI->BanClientID->text().arg(m_Session.clientID)); 22 | m_pUI->BanUserID->setText(m_pUI->BanUserID->text().arg(m_Session.userID)); 23 | 24 | m_pUI->BanTypeBox->addItem("IP"); 25 | 26 | connect(m_pUI->BanBtn, &QPushButton::clicked, this, &CBanDialog::Ban); 27 | connect(m_pUI->CancelBtn, &QPushButton::clicked, this, &CBanDialog::close); 28 | connect(m_pUI->BanTypeBox, &QComboBox::currentTextChanged, this, &CBanDialog::OnBanTypeChanged); 29 | 30 | CheckInfo(); 31 | } 32 | 33 | CBanDialog::~CBanDialog() 34 | { 35 | delete m_pUI; 36 | } 37 | 38 | void CBanDialog::CheckInfo() 39 | { 40 | m_pUI->UserBanTypeBox->setEnabled(false); 41 | m_pUI->ExpiryDateEntry->setEnabled(false); 42 | m_pUI->BanReason->setEnabled(false); 43 | 44 | if (m_Session.userID > 0) 45 | { 46 | m_pUI->BanTypeBox->addItem("User"); 47 | } 48 | 49 | if (!m_Session.hwid.empty()) 50 | { 51 | m_pUI->BanTypeBox->addItem("HWID"); 52 | } 53 | } 54 | 55 | void CBanDialog::Ban() 56 | { 57 | QString banType = m_pUI->BanTypeBox->currentText(); 58 | if (banType == "User") 59 | { 60 | UserBan ban; 61 | 62 | QString userBanType = m_pUI->UserBanTypeBox->currentText(); 63 | if (userBanType == "With message") 64 | ban.banType = 1; 65 | else if (userBanType == "Silent (without showing reason on client)") 66 | ban.banType = 2; 67 | else 68 | ban.banType = 0; 69 | 70 | ban.reason = m_pUI->BanReason->toPlainText().toStdString(); 71 | ban.term = m_pUI->ExpiryDateEntry->dateTime().currentSecsSinceEpoch() / 60; 72 | 73 | if (g_pUserDatabase->UpdateUserBan(m_Session.userID, ban) <= 0) 74 | { 75 | QMessageBox::critical(this, "Error", "An error occured while banning user"); 76 | close(); 77 | } 78 | } 79 | else if (banType == "HWID") 80 | { 81 | if (g_pUserDatabase->UpdateHWIDBanList(m_Session.hwid) <= 0) 82 | { 83 | QMessageBox::critical(this, "Error", "An error occured while banning user"); 84 | close(); 85 | } 86 | } 87 | else if (banType == "IP") 88 | { 89 | if (g_pUserDatabase->UpdateIPBanList(m_Session.ip) <= 0) 90 | { 91 | QMessageBox::critical(this, "Error", "An error occured while banning user"); 92 | close(); 93 | } 94 | } 95 | else 96 | { 97 | QMessageBox::warning(this, "Warning", "Unknown ban type"); 98 | } 99 | 100 | int clientID = m_Session.clientID; 101 | g_pEvents->AddEventFunction([clientID]() 102 | { 103 | g_pServerInstance->DisconnectClient(g_pServerInstance->GetSocketByID(clientID)); 104 | }); 105 | 106 | close(); 107 | setResult(1); 108 | } 109 | 110 | void CBanDialog::OnBanTypeChanged(const QString& text) 111 | { 112 | if (text == "User") 113 | { 114 | m_pUI->UserBanTypeBox->setEnabled(true); 115 | m_pUI->ExpiryDateEntry->setEnabled(true); 116 | m_pUI->BanReason->setEnabled(true); 117 | } 118 | else 119 | { 120 | m_pUI->UserBanTypeBox->setEnabled(false); 121 | m_pUI->ExpiryDateEntry->setEnabled(false); 122 | m_pUI->BanReason->setEnabled(false); 123 | } 124 | } -------------------------------------------------------------------------------- /src/gui/bandialog.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #undef slots 5 | #include "definitions.h" 6 | #define slots Q_SLOTS 7 | 8 | namespace Ui 9 | { 10 | class BanDialog; 11 | } 12 | 13 | class CBanDialog : public QDialog 14 | { 15 | Q_OBJECT 16 | 17 | public: 18 | CBanDialog(QWidget* parent, const Session& session); 19 | ~CBanDialog(); 20 | 21 | public: 22 | void CheckInfo(); 23 | 24 | public slots: 25 | void Ban(); 26 | void OnBanTypeChanged(const QString& text); 27 | 28 | private: 29 | Ui::BanDialog* m_pUI; 30 | Session m_Session; 31 | }; -------------------------------------------------------------------------------- /src/gui/consoletab.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace Ui 7 | { 8 | class ConsoleTab; 9 | } 10 | 11 | class CConsoleTab : public QWidget 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | CConsoleTab(QWidget* parent = nullptr); 17 | ~CConsoleTab(); 18 | 19 | public slots: 20 | void Log(int level, const std::string& msg); 21 | void SubmitClicked(); 22 | void TextChanged(const QString& text); 23 | bool eventFilter(QObject* obj, QEvent* event); 24 | void OnCommandListUpdated(const std::vector& cmdList); 25 | 26 | private: 27 | Ui::ConsoleTab* m_pUI; 28 | QCompleter* m_pCommandList; 29 | QCompleter* m_pCommandHistory; 30 | QStringList m_CmdList; 31 | }; -------------------------------------------------------------------------------- /src/gui/consoletab.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | ConsoleTab 4 | 5 | 6 | 7 | 0 8 | 0 9 | 691 10 | 450 11 | 12 | 13 | 14 | Qt::TabFocus 15 | 16 | 17 | Form 18 | 19 | 20 | 21 | 22 | 10 23 | 10 24 | 671 25 | 391 26 | 27 | 28 | 29 | 30 | Consolas 31 | 32 | 33 | 34 | true 35 | 36 | 37 | Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse 38 | 39 | 40 | 41 | 42 | 43 | 600 44 | 410 45 | 75 46 | 23 47 | 48 | 49 | 50 | Submit 51 | 52 | 53 | false 54 | 55 | 56 | true 57 | 58 | 59 | 60 | 61 | 62 | 10 63 | 410 64 | 581 65 | 23 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /src/gui/gui.cpp: -------------------------------------------------------------------------------- 1 | #include "gui.h" 2 | #include "interface/imanager.h" 3 | 4 | static CGUI g_GUI; 5 | IGUI* g_pGUI = NULL; 6 | 7 | IEvents* g_pEvents = NULL; 8 | IManager* g_pManager = NULL; 9 | IServerInstance* g_pServerInstance = NULL; 10 | IUserManager* g_pUserManager = NULL; 11 | IUserDatabase* g_pUserDatabase = NULL; 12 | IPacketManager* g_pPacketManager = NULL; 13 | 14 | CGUI::CGUI() 15 | { 16 | g_pGUI = this; 17 | m_pApplication = NULL; 18 | m_pMainWindow = NULL; 19 | } 20 | 21 | CGUI::~CGUI() 22 | { 23 | g_pGUI = NULL; 24 | Shutdown(); 25 | } 26 | 27 | bool CGUI::Init(IManager* mgr, IEvents* events) 28 | { 29 | g_pManager = mgr; 30 | g_pEvents = events; 31 | 32 | int argc = 0; 33 | m_pApplication = new QApplication(argc, NULL); 34 | m_pMainWindow = new CMainWindow(); 35 | 36 | return true; 37 | } 38 | 39 | bool CGUI::PostInit(IServerInstance* srv) 40 | { 41 | g_pServerInstance = srv; 42 | if (!g_pServerInstance) 43 | { 44 | ShowMessageBox("Fatal Error", "Could not get ServerInstance interface", true); 45 | return false; 46 | } 47 | 48 | g_pUserManager = (IUserManager*)g_pManager->GetManager("UserManager"); 49 | if (!g_pUserManager) 50 | { 51 | ShowMessageBox("Fatal Error", "Could not get UserManager interface", true); 52 | return false; 53 | } 54 | 55 | g_pUserDatabase = (IUserDatabase*)g_pManager->GetManager("UserDatabase"); 56 | if (!g_pUserDatabase) 57 | { 58 | ShowMessageBox("Fatal Error", "Could not get UserDatabase interface", true); 59 | return false; 60 | } 61 | 62 | g_pPacketManager = (IPacketManager*)g_pManager->GetManager("PacketManager"); 63 | if (!g_pPacketManager) 64 | { 65 | ShowMessageBox("Fatal Error", "Could not get PacketManager interface", true); 66 | return false; 67 | } 68 | 69 | return true; 70 | } 71 | 72 | void CGUI::Shutdown() 73 | { 74 | delete m_pMainWindow; 75 | m_pMainWindow = NULL; 76 | delete m_pApplication; 77 | m_pApplication = NULL; 78 | } 79 | 80 | void CGUI::Exec() 81 | { 82 | int result = m_pApplication->exec(); 83 | } 84 | 85 | void CGUI::Exit() 86 | { 87 | QMetaObject::invokeMethod(m_pApplication, "exit"); 88 | } 89 | 90 | void CGUI::LogMessage(int level, const std::string& msg) 91 | { 92 | if (m_pMainWindow) 93 | QMetaObject::invokeMethod(m_pMainWindow->GetConsoleTab(), "Log", Q_ARG(int, level), Q_ARG(const std::string&, msg)); 94 | } 95 | 96 | void CGUI::UpdateInfo(int status, int totalConnections, int uptime, double memoryUsage) 97 | { 98 | if (m_pMainWindow) 99 | QMetaObject::invokeMethod(m_pMainWindow->GetMainTab(), "UpdateInfo", Q_ARG(int, status), Q_ARG(int, totalConnections), Q_ARG(int, uptime), Q_ARG(double, memoryUsage)); 100 | } 101 | 102 | void CGUI::ShowMessageBox(const std::string& title, const std::string& msg, bool fatalError) 103 | { 104 | if (m_pMainWindow) 105 | QMetaObject::invokeMethod(m_pMainWindow, "ShowMessageBox", Q_ARG(const std::string&, title), Q_ARG(const std::string&, msg), Q_ARG(bool, fatalError)); 106 | } 107 | 108 | void CGUI::ShowMainWindow() 109 | { 110 | if (m_pMainWindow) 111 | QMetaObject::invokeMethod(m_pMainWindow, "show"); 112 | } 113 | 114 | void CGUI::OnSessionListUpdated(const std::vector& sessions) 115 | { 116 | if (m_pMainWindow) 117 | QMetaObject::invokeMethod(m_pMainWindow->GetSessionTab(), "OnSessionListUpdated", Q_ARG(const std::vector&, sessions)); 118 | } 119 | 120 | void CGUI::OnCommandListUpdated(const std::vector& cmdList) 121 | { 122 | if (m_pMainWindow) 123 | QMetaObject::invokeMethod(m_pMainWindow->GetConsoleTab(), "OnCommandListUpdated", Q_ARG(const std::vector&, cmdList)); 124 | } -------------------------------------------------------------------------------- /src/gui/gui.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "igui.h" 4 | #include "mainwindow.h" 5 | #undef slots // undef keyword to avoid conflict 6 | //#include "IUserManager.h" 7 | //#include "IUserDatabase.h" 8 | #define slots Q_SLOTS 9 | 10 | #include 11 | 12 | class CGUI : public IGUI 13 | { 14 | public: 15 | CGUI(); 16 | virtual ~CGUI(); 17 | 18 | virtual bool Init(IManager* mgr, IEvents* events); 19 | virtual bool PostInit(IServerInstance* srv); 20 | virtual void Shutdown(); 21 | virtual void Exec(); 22 | 23 | // thread safe methods to update GUI 24 | virtual void Exit(); 25 | virtual void LogMessage(int level, const std::string& msg); 26 | virtual void UpdateInfo(int status, int totalConnections, int uptime, double memoryUsage); 27 | virtual void ShowMessageBox(const std::string& title, const std::string& msg, bool fatalError = false); 28 | virtual void ShowMainWindow(); 29 | virtual void OnSessionListUpdated(const std::vector& sessions); 30 | virtual void OnCommandListUpdated(const std::vector& cmdList); 31 | 32 | private: 33 | QApplication* m_pApplication; 34 | CMainWindow* m_pMainWindow; 35 | }; 36 | 37 | extern IEvents* g_pEvents; 38 | extern IManager* g_pManager; 39 | extern IServerInstance* g_pServerInstance; 40 | extern class IPacketManager* g_pPacketManager; 41 | extern class IUserManager* g_pUserManager; 42 | extern class IUserDatabase* g_pUserDatabase; -------------------------------------------------------------------------------- /src/gui/hwidbanlistdialog.cpp: -------------------------------------------------------------------------------- 1 | #include "hwidbanlistdialog.h" 2 | #include 3 | #include 4 | 5 | #include "gui.h" 6 | #include "interface/iuserdatabase.h" 7 | 8 | CHWIDBanListDialog::CHWIDBanListDialog(QWidget* parent) : QDialog(parent) 9 | { 10 | m_pUI = new Ui::HWIDBanListDialog(); 11 | m_pUI->setupUi(this); 12 | 13 | connect(m_pUI->UnbanBtn, &QPushButton::clicked, this, &CHWIDBanListDialog::Unban); 14 | connect(m_pUI->HWIDList, &QListWidget::currentItemChanged, this, &CHWIDBanListDialog::OnSelectHWID); 15 | 16 | InitBanList(); 17 | } 18 | 19 | CHWIDBanListDialog::~CHWIDBanListDialog() 20 | { 21 | delete m_pUI; 22 | } 23 | 24 | void CHWIDBanListDialog::InitBanList() 25 | { 26 | std::vector> banList = g_pUserDatabase->GetHWIDBanList(); 27 | 28 | m_pUI->HWIDList->clear(); 29 | 30 | for (auto& hwid : banList) 31 | { 32 | QByteArray arr(reinterpret_cast(hwid.data()), hwid.size()); 33 | m_pUI->HWIDList->addItem(new QListWidgetItem(QString(arr.toHex()))); 34 | } 35 | } 36 | 37 | void CHWIDBanListDialog::Unban() 38 | { 39 | QListWidgetItem* item = m_pUI->HWIDList->currentItem(); 40 | if (item) 41 | { 42 | QByteArray arr = QByteArray::fromHex(item->text().toLocal8Bit()); 43 | 44 | if (g_pUserDatabase->UpdateHWIDBanList(std::vector(arr.begin(), arr.end()), true) <= 0) 45 | { 46 | QMessageBox::critical(this, "Error", "An error occured while updating ban list"); 47 | } 48 | else 49 | { 50 | m_pUI->HWIDList->removeItemWidget(item); 51 | delete item; 52 | } 53 | } 54 | } 55 | 56 | void CHWIDBanListDialog::OnSelectHWID(QListWidgetItem* current, QListWidgetItem* previous) 57 | { 58 | if (!current) 59 | return; 60 | 61 | std::vector users; 62 | QByteArray arr = QByteArray::fromHex(current->text().toLocal8Bit()); 63 | 64 | if (g_pUserDatabase->GetUsersAssociatedWithHWID(std::vector(arr.begin(), arr.end()), users) <= 0) 65 | { 66 | QMessageBox::critical(this, "Error", "An error occured while getting users"); 67 | return; 68 | } 69 | 70 | m_pUI->UserList->clearContents(); 71 | m_pUI->UserList->model()->removeRows(0, m_pUI->UserList->rowCount()); 72 | 73 | int row = 0; 74 | for (auto& data : users) 75 | { 76 | m_pUI->UserList->insertRow(row); 77 | m_pUI->UserList->setItem(row, 0, new QTableWidgetItem(QString::number(data.userID))); 78 | m_pUI->UserList->setItem(row, 1, new QTableWidgetItem(data.userName.c_str())); 79 | row++; 80 | } 81 | } 82 | 83 | -------------------------------------------------------------------------------- /src/gui/hwidbanlistdialog.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace Ui 6 | { 7 | class HWIDBanListDialog; 8 | } 9 | 10 | class QListWidgetItem; 11 | 12 | class CHWIDBanListDialog : public QDialog 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | CHWIDBanListDialog(QWidget* parent); 18 | ~CHWIDBanListDialog(); 19 | 20 | public slots: 21 | void Unban(); 22 | void OnSelectHWID(QListWidgetItem* current, QListWidgetItem* previous); 23 | 24 | private: 25 | void InitBanList(); 26 | 27 | private: 28 | Ui::HWIDBanListDialog* m_pUI; 29 | }; -------------------------------------------------------------------------------- /src/gui/hwidbanlistdialog.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | HWIDBanListDialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 540 10 | 330 11 | 12 | 13 | 14 | 15 | 540 16 | 330 17 | 18 | 19 | 20 | HWID ban list 21 | 22 | 23 | Qt::LeftToRight 24 | 25 | 26 | false 27 | 28 | 29 | true 30 | 31 | 32 | false 33 | 34 | 35 | 36 | 37 | 38 | 39 | 0 40 | 0 41 | 42 | 43 | 44 | 45 | 200 46 | 16777215 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 0 56 | 0 57 | 58 | 59 | 60 | Unban 61 | 62 | 63 | 64 | 65 | 66 | 67 | Click on HWID from the first list to check which users are associated with it 68 | 69 | 70 | 71 | 72 | 73 | 74 | QAbstractItemView::SelectRows 75 | 76 | 77 | false 78 | 79 | 80 | true 81 | 82 | 83 | false 84 | 85 | 86 | 87 | UserID 88 | 89 | 90 | 91 | 92 | Username 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /src/gui/igui.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #undef slots 5 | #include "definitions.h" 6 | #define slots Q_SLOTS 7 | 8 | class IServerInstance; 9 | class IManager; 10 | class IEvents; 11 | 12 | class IGUI 13 | { 14 | public: 15 | virtual bool Init(IManager* mgr, IEvents* events) = 0; 16 | virtual bool PostInit(IServerInstance* srv) = 0; 17 | virtual void Shutdown() = 0; 18 | virtual void Exec() = 0; 19 | 20 | // thread safe methods to update GUI 21 | virtual void Exit() = 0; 22 | virtual void LogMessage(int level, const std::string& msg) = 0; 23 | virtual void UpdateInfo(int status, int totalConnections, int uptime, double memoryUsage) = 0; 24 | virtual void ShowMessageBox(const std::string& title, const std::string& msg, bool fatalError = false) = 0; 25 | virtual void ShowMainWindow() = 0; 26 | virtual void OnSessionListUpdated(const std::vector& sessions) = 0; 27 | virtual void OnCommandListUpdated(const std::vector& cmdList) = 0; 28 | }; 29 | 30 | inline IGUI* GUI() 31 | { 32 | extern IGUI* g_pGUI; 33 | return g_pGUI; 34 | } -------------------------------------------------------------------------------- /src/gui/ipbanlistdialog.cpp: -------------------------------------------------------------------------------- 1 | #include "ipbanlistdialog.h" 2 | #include 3 | #include 4 | 5 | #include "gui.h" 6 | #include "interface/iuserdatabase.h" 7 | 8 | CIPBanListDialog::CIPBanListDialog(QWidget* parent) : QDialog(parent) 9 | { 10 | m_pUI = new Ui::IPBanListDialog(); 11 | m_pUI->setupUi(this); 12 | 13 | connect(m_pUI->UnbanBtn, &QPushButton::clicked, this, &CIPBanListDialog::Unban); 14 | connect(m_pUI->IPList, &QListWidget::currentItemChanged, this, &CIPBanListDialog::OnSelectIP); 15 | 16 | InitBanList(); 17 | } 18 | 19 | CIPBanListDialog::~CIPBanListDialog() 20 | { 21 | delete m_pUI; 22 | } 23 | 24 | void CIPBanListDialog::InitBanList() 25 | { 26 | std::vector banList = g_pUserDatabase->GetIPBanList(); 27 | 28 | m_pUI->IPList->clear(); 29 | 30 | for (auto& ip : banList) 31 | { 32 | m_pUI->IPList->addItem(new QListWidgetItem(QString::fromStdString(ip))); 33 | } 34 | } 35 | 36 | void CIPBanListDialog::Unban() 37 | { 38 | QListWidgetItem* item = m_pUI->IPList->currentItem(); 39 | if (item) 40 | { 41 | if (g_pUserDatabase->UpdateIPBanList(item->text().toStdString(), true) <= 0) 42 | { 43 | QMessageBox::critical(this, "Error", "An error occured while updating ban list"); 44 | } 45 | else 46 | { 47 | m_pUI->IPList->removeItemWidget(item); 48 | delete item; 49 | } 50 | } 51 | } 52 | 53 | void CIPBanListDialog::OnSelectIP(QListWidgetItem* current, QListWidgetItem* previous) 54 | { 55 | m_pUI->UserList->clearContents(); 56 | m_pUI->UserList->model()->removeRows(0, m_pUI->UserList->rowCount()); 57 | 58 | if (!current) 59 | { 60 | return; 61 | } 62 | 63 | std::vector users; 64 | if (g_pUserDatabase->GetUsersAssociatedWithIP(current->text().toStdString(), users) <= 0) 65 | { 66 | QMessageBox::critical(this, "Error", "An error occured while getting users"); 67 | return; 68 | } 69 | 70 | int row = 0; 71 | for (auto& data : users) 72 | { 73 | m_pUI->UserList->insertRow(row); 74 | m_pUI->UserList->setItem(row, 0, new QTableWidgetItem(QString::number(data.userID))); 75 | m_pUI->UserList->setItem(row, 1, new QTableWidgetItem(data.userName.c_str())); 76 | row++; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/gui/ipbanlistdialog.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace Ui 6 | { 7 | class IPBanListDialog; 8 | } 9 | 10 | class QListWidgetItem; 11 | 12 | class CIPBanListDialog : public QDialog 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | CIPBanListDialog(QWidget* parent); 18 | ~CIPBanListDialog(); 19 | 20 | public slots: 21 | void Unban(); 22 | void OnSelectIP(QListWidgetItem* current, QListWidgetItem* previous); 23 | 24 | private: 25 | void InitBanList(); 26 | 27 | private: 28 | Ui::IPBanListDialog* m_pUI; 29 | }; -------------------------------------------------------------------------------- /src/gui/ipbanlistdialog.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | IPBanListDialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 540 10 | 330 11 | 12 | 13 | 14 | 15 | 540 16 | 330 17 | 18 | 19 | 20 | IP ban list 21 | 22 | 23 | Qt::LeftToRight 24 | 25 | 26 | false 27 | 28 | 29 | true 30 | 31 | 32 | false 33 | 34 | 35 | 36 | 37 | 38 | 39 | 0 40 | 0 41 | 42 | 43 | 44 | Unban 45 | 46 | 47 | 48 | 49 | 50 | 51 | Click on IP from the first list to check which users are associated with it 52 | 53 | 54 | 55 | 56 | 57 | 58 | QAbstractItemView::SelectRows 59 | 60 | 61 | false 62 | 63 | 64 | true 65 | 66 | 67 | true 68 | 69 | 70 | false 71 | 72 | 73 | 74 | UserID 75 | 76 | 77 | 78 | 79 | Username 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 0 89 | 0 90 | 91 | 92 | 93 | 94 | 140 95 | 16777215 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /src/gui/maintab.cpp: -------------------------------------------------------------------------------- 1 | #include "maintab.h" 2 | #include "common/utils.h" 3 | #include "noticedialog.h" 4 | #include "userbanlistdialog.h" 5 | #include "hwidbanlistdialog.h" 6 | #include "ipbanlistdialog.h" 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | const int TIMEOUT_TIME = 120000; // 2 minutes in ms 14 | 15 | CMainTab::CMainTab(QWidget* parent) : QWidget(parent) 16 | { 17 | m_pUI = new Ui::MainTab(); 18 | m_pUI->setupUi(this); 19 | 20 | m_nConnectedClients = 0; 21 | 22 | m_pServerHeartbeatTimer = new QTimer(this); 23 | m_pServerHeartbeatTimer->setInterval(TIMEOUT_TIME); 24 | 25 | connect(m_pUI->SendNoticeBtn, &QPushButton::clicked, this, &CMainTab::SendNoticeBtnClicked); 26 | connect(m_pUI->UserBanListBtn, &QPushButton::clicked, this, &CMainTab::OpenUserBanList); 27 | connect(m_pUI->IPBanListBtn, &QPushButton::clicked, this, &CMainTab::OpenIPBanList); 28 | connect(m_pUI->HWIDBanListBtn, &QPushButton::clicked, this, &CMainTab::OpenHWIDBanList); 29 | connect(m_pUI->ConfigEditorBtn, &QPushButton::clicked, this, [=]() { QMessageBox::warning(this, "Warning", "Unimplemented"); }); 30 | connect(m_pUI->DelayedShutdownBtn, &QPushButton::clicked, this, [=]() { QMessageBox::warning(this, "Warning", "Unimplemented"); }); 31 | 32 | connect(m_pServerHeartbeatTimer, &QTimer::timeout, this, &CMainTab::ServerTimeout); 33 | 34 | m_pServerHeartbeatTimer->start(); 35 | } 36 | 37 | CMainTab::~CMainTab() 38 | { 39 | delete m_pUI; 40 | } 41 | 42 | int CMainTab::GetConnectedClients() 43 | { 44 | return m_nConnectedClients; 45 | } 46 | 47 | // update main tab info 48 | void CMainTab::UpdateInfo(int status, int totalConnections, int uptime, double memoryUsage) 49 | { 50 | m_nConnectedClients = totalConnections; 51 | 52 | m_pUI->ServerStatusLabel->setText(QString("Server status: %1").arg(status)); 53 | m_pUI->ClientNumberLabel->setText(QString("Total connection: %1").arg(totalConnections)); 54 | m_pUI->UptimeLabel->setText(QString("Uptime: %1").arg(FormatSeconds(uptime))); 55 | m_pUI->MemUsageLabel->setText(QString("Memory usage: %1mb").arg(memoryUsage, 0, 'f', 3)); 56 | 57 | m_pServerHeartbeatTimer->start(); 58 | } 59 | 60 | void CMainTab::SendNoticeBtnClicked() 61 | { 62 | CNoticeDialog noticeDialog(this); 63 | noticeDialog.exec(); 64 | } 65 | 66 | void CMainTab::OpenUserBanList() 67 | { 68 | CUserBanListDialog dlg(this); 69 | dlg.exec(); 70 | } 71 | 72 | void CMainTab::OpenIPBanList() 73 | { 74 | CIPBanListDialog dlg(this); 75 | dlg.exec(); 76 | } 77 | 78 | void CMainTab::OpenHWIDBanList() 79 | { 80 | CHWIDBanListDialog dlg(this); 81 | dlg.exec(); 82 | } 83 | 84 | void CMainTab::ServerTimeout() 85 | { 86 | m_pServerHeartbeatTimer->stop(); 87 | QMessageBox::warning(this, "Warning", QString("The server does not respond for more than %1 seconds.").arg(TIMEOUT_TIME / 1000)); 88 | } 89 | -------------------------------------------------------------------------------- /src/gui/maintab.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace Ui 6 | { 7 | class MainTab; 8 | } 9 | 10 | class CMainTab : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | CMainTab(QWidget* parent = nullptr); 16 | ~CMainTab(); 17 | 18 | int GetConnectedClients(); 19 | 20 | public slots: 21 | void UpdateInfo(int status, int totalConnections, int uptime, double memoryUsage); 22 | void SendNoticeBtnClicked(); 23 | void OpenUserBanList(); 24 | void OpenIPBanList(); 25 | void OpenHWIDBanList(); 26 | void ServerTimeout(); 27 | 28 | private: 29 | Ui::MainTab* m_pUI; 30 | QTimer* m_pServerHeartbeatTimer; 31 | int m_nConnectedClients; 32 | }; -------------------------------------------------------------------------------- /src/gui/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | #include "gui.h" 5 | #include "interface/ievent.h" 6 | #include "interface/iusermanager.h" 7 | 8 | #include 9 | #include 10 | 11 | CMainWindow::CMainWindow() : QMainWindow(NULL) 12 | { 13 | m_pUI = new Ui::MainWindow(); 14 | m_pUI->setupUi(this); 15 | 16 | m_pMainTab = new CMainTab(); 17 | m_pConsoleTab = new CConsoleTab(); 18 | m_pSessionTab = new CSessionTab(); 19 | m_pRoomListTab = new CRoomListTab(); 20 | 21 | m_pUI->tabWidget->addTab(m_pMainTab, "Main"); 22 | m_pUI->tabWidget->addTab(m_pConsoleTab, "Console"); 23 | m_pUI->tabWidget->addTab(m_pSessionTab, "Session"); 24 | //m_pUI->tabWidget->addTab(m_pRoomListTab, "Room list"); 25 | } 26 | 27 | CMainWindow::~CMainWindow() 28 | { 29 | delete m_pUI; 30 | delete m_pMainTab; 31 | delete m_pConsoleTab; 32 | delete m_pSessionTab; 33 | delete m_pRoomListTab; 34 | } 35 | 36 | CMainTab* CMainWindow::GetMainTab() 37 | { 38 | return m_pMainTab; 39 | } 40 | 41 | CConsoleTab* CMainWindow::GetConsoleTab() 42 | { 43 | return m_pConsoleTab; 44 | } 45 | 46 | CSessionTab* CMainWindow::GetSessionTab() 47 | { 48 | return m_pSessionTab; 49 | } 50 | 51 | void CMainWindow::ShowMessageBox(const std::string& title, const std::string& msg, bool fatalError) 52 | { 53 | if (fatalError) 54 | { 55 | QMessageBox::critical(this, QString::fromStdString(title), QString::fromStdString(msg)); 56 | QApplication::exit(); 57 | } 58 | else 59 | { 60 | QMessageBox::information(this, QString::fromStdString(title), QString::fromStdString(msg)); 61 | } 62 | } 63 | 64 | // handle close event to warn user that there are still users on the server 65 | void CMainWindow::closeEvent(QCloseEvent* event) 66 | { 67 | QMessageBox msgBox; 68 | 69 | QPushButton* quitAndSendMaintenanceMsgBtn = NULL; 70 | if (m_pMainTab->GetConnectedClients() > 0) 71 | quitAndSendMaintenanceMsgBtn = msgBox.addButton("Quit and send maintenance message", QMessageBox::ActionRole); 72 | 73 | QPushButton* quitBtn = msgBox.addButton("Quit", QMessageBox::ActionRole); 74 | QPushButton* cancelBtn = msgBox.addButton(QMessageBox::Cancel); 75 | msgBox.setWindowTitle("Quit"); 76 | msgBox.setText("Do you wish to stop the server now?"); 77 | 78 | msgBox.exec(); 79 | 80 | if (msgBox.clickedButton() == (QAbstractButton*)quitAndSendMaintenanceMsgBtn) 81 | { 82 | // send maintenance msg to all users and quit 83 | g_pEvents->AddEventFunction([]() 84 | { 85 | g_pUserManager->SendNoticeMsgBoxToAll("Server down for maintenance"); 86 | }); 87 | 88 | event->accept(); 89 | } 90 | else if (msgBox.clickedButton() == (QAbstractButton*)quitBtn) 91 | { 92 | // just quit 93 | event->accept(); 94 | } 95 | else 96 | { 97 | event->ignore(); 98 | } 99 | } -------------------------------------------------------------------------------- /src/gui/mainwindow.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "MainTab.h" 7 | #include "ConsoleTab.h" 8 | #include "SessionTab.h" 9 | #include "RoomListTab.h" 10 | 11 | namespace Ui 12 | { 13 | class MainWindow; 14 | } 15 | 16 | class CMainWindow : public QMainWindow 17 | { 18 | Q_OBJECT 19 | 20 | public: 21 | CMainWindow(); 22 | ~CMainWindow(); 23 | 24 | CMainTab* GetMainTab(); 25 | CConsoleTab* GetConsoleTab(); 26 | CSessionTab* GetSessionTab(); 27 | 28 | public slots: 29 | void ShowMessageBox(const std::string& title, const std::string& msg, bool fatalError = 0); 30 | 31 | protected: 32 | void closeEvent(QCloseEvent* event); 33 | 34 | private: 35 | Ui::MainWindow* m_pUI; 36 | 37 | // tabs 38 | CMainTab* m_pMainTab; 39 | CConsoleTab* m_pConsoleTab; 40 | CSessionTab* m_pSessionTab; 41 | CRoomListTab* m_pRoomListTab; 42 | }; -------------------------------------------------------------------------------- /src/gui/mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | true 7 | 8 | 9 | 10 | 0 11 | 0 12 | 700 13 | 500 14 | 15 | 16 | 17 | 18 | 0 19 | 0 20 | 21 | 22 | 23 | 24 | 700 25 | 500 26 | 27 | 28 | 29 | 30 | 700 31 | 500 32 | 33 | 34 | 35 | MainWindow 36 | 37 | 38 | false 39 | 40 | 41 | 42 | 43 | 44 | QMainWindow::AllowTabbedDocks|QMainWindow::AnimatedDocks 45 | 46 | 47 | false 48 | 49 | 50 | 51 | 52 | true 53 | 54 | 55 | 56 | 0 57 | 0 58 | 691 59 | 471 60 | 61 | 62 | 63 | -1 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /src/gui/noticedialog.cpp: -------------------------------------------------------------------------------- 1 | #include "noticedialog.h" 2 | #include "selectuserdialog.h" 3 | 4 | #include "gui.h" 5 | #include "interface/iusermanager.h" 6 | #include "interface/ipacketmanager.h" 7 | #include "interface/ievent.h" 8 | 9 | #include 10 | #include 11 | 12 | #define MAX_TEXT_LEN 128 13 | 14 | CNoticeDialog::CNoticeDialog(QWidget* parent) : QDialog(parent) 15 | { 16 | m_pUI = new Ui::NoticeDialog(); 17 | m_pUI->setupUi(this); 18 | 19 | setWindowFlags(windowFlags() | Qt::MSWindowsFixedSizeDialogHint); 20 | 21 | connect(m_pUI->CancelBtn, SIGNAL(clicked()), this, SLOT(close())); 22 | connect(m_pUI->SendBtn, SIGNAL(clicked()), this, SLOT(SendClicked())); 23 | connect(m_pUI->SelectUsersBtn, SIGNAL(clicked()), this, SLOT(SelectUsersClicked())); 24 | connect(m_pUI->NotificationTextEdit, SIGNAL(textChanged()), this, SLOT(TextChanged())); 25 | } 26 | 27 | CNoticeDialog::~CNoticeDialog() 28 | { 29 | delete m_pUI; 30 | } 31 | 32 | void CNoticeDialog::SendClicked() 33 | { 34 | QString text = m_pUI->NotificationTextEdit->toPlainText(); 35 | if (text.isEmpty()) 36 | { 37 | QMessageBox::warning(this, "Warning", "You have not entered anything in the text field."); 38 | return; 39 | } 40 | 41 | if (m_SelectedUsers.empty()) 42 | { 43 | QMessageBox::warning(this, "Warning", "You have not selected any users."); 44 | return; 45 | } 46 | 47 | std::string str = text.toStdString(); 48 | std::vector users = m_SelectedUsers; 49 | g_pEvents->AddEventFunction([str, users]() 50 | { 51 | for (auto userID : users) 52 | { 53 | IUser* user = g_pUserManager->GetUserById(userID); 54 | if (user) 55 | { 56 | g_pPacketManager->SendUMsgNoticeMsgBoxToUuid(user->GetExtendedSocket(), str); 57 | } 58 | } 59 | }); 60 | 61 | close(); 62 | } 63 | 64 | void CNoticeDialog::SelectUsersClicked() 65 | { 66 | CSelectUserDialog selectUserDialog(this, m_SelectedUsers); 67 | if (selectUserDialog.exec() == 1) 68 | m_SelectedUsers = selectUserDialog.GetSelectedUsers(); 69 | } 70 | 71 | void CNoticeDialog::TextChanged() 72 | { 73 | // TODO: don't put characters when limit is exceeded if cursor is not at end 74 | m_pUI->NotificationTextEdit->blockSignals(true); 75 | 76 | // check for characters limit 77 | QString text = m_pUI->NotificationTextEdit->toPlainText(); 78 | if (text.length() > MAX_TEXT_LEN) 79 | { 80 | text.chop(text.length() - MAX_TEXT_LEN); // cut text after 128 character 81 | m_pUI->NotificationTextEdit->setPlainText(text); 82 | 83 | QTextCursor cursor(m_pUI->NotificationTextEdit->textCursor()); 84 | cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor); 85 | m_pUI->NotificationTextEdit->setTextCursor(cursor); 86 | } 87 | 88 | m_pUI->NotificationTextEdit->blockSignals(false); 89 | } -------------------------------------------------------------------------------- /src/gui/noticedialog.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace Ui 6 | { 7 | class NoticeDialog; 8 | } 9 | 10 | class CNoticeDialog : public QDialog 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | CNoticeDialog(QWidget* parent = nullptr); 16 | ~CNoticeDialog(); 17 | 18 | public slots: 19 | void SendClicked(); 20 | void SelectUsersClicked(); 21 | void TextChanged(); 22 | 23 | private: 24 | Ui::NoticeDialog* m_pUI; 25 | std::vector m_SelectedUsers; 26 | }; -------------------------------------------------------------------------------- /src/gui/noticedialog.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | NoticeDialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 400 10 | 300 11 | 12 | 13 | 14 | Send notice 15 | 16 | 17 | 18 | 19 | 10 20 | 20 21 | 381 22 | 241 23 | 24 | 25 | 26 | 27 | 28 | 29 | 10 30 | 0 31 | 311 32 | 20 33 | 34 | 35 | 36 | Enter notification text (max. 128 characters) 37 | 38 | 39 | 40 | 41 | 42 | 130 43 | 270 44 | 81 45 | 23 46 | 47 | 48 | 49 | Choose users 50 | 51 | 52 | 53 | 54 | 55 | 220 56 | 270 57 | 81 58 | 23 59 | 60 | 61 | 62 | Send 63 | 64 | 65 | 66 | 67 | 68 | 310 69 | 270 70 | 81 71 | 23 72 | 73 | 74 | 75 | Cancel 76 | 77 | 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /src/gui/roomlisttab.cpp: -------------------------------------------------------------------------------- 1 | #include "roomlisttab.h" 2 | #include 3 | 4 | CRoomListTab::CRoomListTab(QWidget* parent) : QWidget(parent) 5 | { 6 | m_pUI = new Ui::RoomListTab(); 7 | m_pUI->setupUi(this); 8 | } 9 | 10 | CRoomListTab::~CRoomListTab() 11 | { 12 | delete m_pUI; 13 | } -------------------------------------------------------------------------------- /src/gui/roomlisttab.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace Ui 6 | { 7 | class RoomListTab; 8 | } 9 | 10 | class CRoomListTab : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | CRoomListTab(QWidget* parent = nullptr); 16 | ~CRoomListTab(); 17 | 18 | private: 19 | Ui::RoomListTab* m_pUI; 20 | }; -------------------------------------------------------------------------------- /src/gui/roomlisttab.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | RoomListTab 4 | 5 | 6 | 7 | 0 8 | 0 9 | 691 10 | 450 11 | 12 | 13 | 14 | Qt::TabFocus 15 | 16 | 17 | Form 18 | 19 | 20 | 21 | 22 | 10 23 | 10 24 | 671 25 | 391 26 | 27 | 28 | 29 | QAbstractItemView::SelectRows 30 | 31 | 32 | false 33 | 34 | 35 | true 36 | 37 | 38 | false 39 | 40 | 41 | false 42 | 43 | 44 | 45 | ID 46 | 47 | 48 | 49 | 50 | Name 51 | 52 | 53 | 54 | 55 | Game mode 56 | 57 | 58 | 59 | 60 | Map 61 | 62 | 63 | 64 | 65 | Players 66 | 67 | 68 | 69 | 70 | Status 71 | 72 | 73 | 74 | 75 | Uptime 76 | 77 | 78 | 79 | 80 | 81 | 82 | 600 83 | 410 84 | 75 85 | 23 86 | 87 | 88 | 89 | Refresh 90 | 91 | 92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /src/gui/selectuserdialog.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace Ui 6 | { 7 | class SelectUserDialog; 8 | } 9 | 10 | class CSelectUserDialog : public QDialog 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | CSelectUserDialog(QWidget* parent, const std::vector& users); 16 | ~CSelectUserDialog(); 17 | 18 | std::vector GetSelectedUsers(); 19 | void InitUserList(); 20 | 21 | public slots: 22 | void SelectClicked(); 23 | void AddUserClicked(); 24 | void DeleteUserClicked(); 25 | 26 | private: 27 | Ui::SelectUserDialog* m_pUI; 28 | std::vector m_SelectedUsers; 29 | }; -------------------------------------------------------------------------------- /src/gui/sessiontab.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #undef slots 5 | #include "definitions.h" 6 | #define slots Q_SLOTS 7 | 8 | namespace Ui 9 | { 10 | class SessionTab; 11 | } 12 | 13 | class CSessionTab : public QWidget 14 | { 15 | Q_OBJECT 16 | 17 | public: 18 | CSessionTab(QWidget* parent = nullptr); 19 | ~CSessionTab(); 20 | 21 | public: 22 | void OnOpenUserCharacterDialog(int userID); 23 | 24 | public slots: 25 | void Refresh(); 26 | void Kick(); 27 | void Ban(); 28 | void ShowOnlyLoggedInToggled(bool checked); 29 | void keyPressEvent(QKeyEvent* event); 30 | void OnSessionListUpdated(const std::vector& sessions); 31 | void HandleContextMenu(const QPoint& pos); 32 | 33 | private: 34 | Ui::SessionTab* m_pUI; 35 | bool m_bRefresing; 36 | std::vector m_Sessions; 37 | }; -------------------------------------------------------------------------------- /src/gui/sessiontab.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | SessionTab 4 | 5 | 6 | 7 | 0 8 | 0 9 | 691 10 | 450 11 | 12 | 13 | 14 | Qt::TabFocus 15 | 16 | 17 | Form 18 | 19 | 20 | 21 | 22 | 10 23 | 10 24 | 671 25 | 391 26 | 27 | 28 | 29 | QAbstractItemView::NoEditTriggers 30 | 31 | 32 | QAbstractItemView::SelectRows 33 | 34 | 35 | false 36 | 37 | 38 | true 39 | 40 | 41 | false 42 | 43 | 44 | false 45 | 46 | 47 | 48 | ID 49 | 50 | 51 | 52 | 53 | User ID 54 | 55 | 56 | 57 | 58 | IP 59 | 60 | 61 | 62 | 63 | Username 64 | 65 | 66 | 67 | 68 | Uptime 69 | 70 | 71 | 72 | 73 | Status 74 | 75 | 76 | 77 | 78 | 79 | 80 | 10 81 | 410 82 | 181 83 | 20 84 | 85 | 86 | 87 | Show only logged in users 88 | 89 | 90 | 91 | 92 | 93 | 600 94 | 410 95 | 75 96 | 23 97 | 98 | 99 | 100 | Refresh 101 | 102 | 103 | 104 | 105 | 106 | 520 107 | 410 108 | 75 109 | 23 110 | 111 | 112 | 113 | Kick 114 | 115 | 116 | 117 | 118 | 119 | 440 120 | 410 121 | 75 122 | 23 123 | 124 | 125 | 126 | Ban 127 | 128 | 129 | 130 | 131 | 132 | 133 | -------------------------------------------------------------------------------- /src/gui/userbanlistdialog.cpp: -------------------------------------------------------------------------------- 1 | #include "UserBanListDialog.h" 2 | #include 3 | #include 4 | #include 5 | 6 | #include "gui.h" 7 | #include "interface/iuserdatabase.h" 8 | 9 | CUserBanListDialog::CUserBanListDialog(QWidget* parent) : QDialog(parent) 10 | { 11 | m_pUI = new Ui::UserBanListDialog(); 12 | m_pUI->setupUi(this); 13 | 14 | connect(m_pUI->UnbanBtn, &QPushButton::clicked, this, &CUserBanListDialog::Unban); 15 | 16 | InitBanList(); 17 | } 18 | 19 | CUserBanListDialog::~CUserBanListDialog() 20 | { 21 | delete m_pUI; 22 | } 23 | 24 | void CUserBanListDialog::InitBanList() 25 | { 26 | std::map banList = g_pUserDatabase->GetUserBanList(); 27 | 28 | int row = 0; 29 | for (auto& b : banList) 30 | { 31 | int userID = b.first; 32 | UserBan ban = b.second; 33 | 34 | m_pUI->UserList->insertRow(row); 35 | m_pUI->UserList->setItem(row, 0, new QTableWidgetItem(QString::number(userID))); 36 | m_pUI->UserList->setItem(row, 1, new QTableWidgetItem("")); 37 | m_pUI->UserList->setItem(row, 2, new QTableWidgetItem(QString::number(ban.banType))); 38 | m_pUI->UserList->setItem(row, 3, new QTableWidgetItem(QDateTime::fromSecsSinceEpoch(ban.term * 60).toString("yyyy-MM-dd hh:mm:ss"))); 39 | m_pUI->UserList->setItem(row, 4, new QTableWidgetItem(ban.reason.c_str())); 40 | } 41 | } 42 | 43 | void CUserBanListDialog::Unban() 44 | { 45 | std::vector userList; 46 | 47 | QItemSelectionModel* selections = m_pUI->UserList->selectionModel(); 48 | QModelIndexList selected = selections->selectedRows(); 49 | while (!selected.isEmpty()) 50 | { 51 | const QModelIndex& idx = selected.at(0); 52 | 53 | int userID = m_pUI->UserList->item(idx.row(), 0)->text().toInt(); 54 | userList.push_back(userID); 55 | 56 | m_pUI->UserList->removeRow(idx.row()); 57 | selected = selections->selectedRows(); 58 | } 59 | 60 | UserBan ban; 61 | ban.banType = 0; // delete ban 62 | for (auto userID : userList) 63 | { 64 | g_pUserDatabase->UpdateUserBan(userID, ban); 65 | } 66 | } -------------------------------------------------------------------------------- /src/gui/userbanlistdialog.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace Ui 6 | { 7 | class UserBanListDialog; 8 | } 9 | 10 | class CUserBanListDialog : public QDialog 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | CUserBanListDialog(QWidget* parent); 16 | ~CUserBanListDialog(); 17 | 18 | public slots: 19 | void Unban(); 20 | 21 | private: 22 | void InitBanList(); 23 | 24 | private: 25 | Ui::UserBanListDialog* m_pUI; 26 | }; -------------------------------------------------------------------------------- /src/gui/userbanlistdialog.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | UserBanListDialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 540 10 | 330 11 | 12 | 13 | 14 | 15 | 540 16 | 330 17 | 18 | 19 | 20 | User ban list 21 | 22 | 23 | Qt::LeftToRight 24 | 25 | 26 | false 27 | 28 | 29 | true 30 | 31 | 32 | false 33 | 34 | 35 | 36 | 37 | 38 | 39 | 0 40 | 0 41 | 42 | 43 | 44 | Unban 45 | 46 | 47 | 48 | 49 | 50 | 51 | QAbstractItemView::SelectRows 52 | 53 | 54 | false 55 | 56 | 57 | true 58 | 59 | 60 | true 61 | 62 | 63 | false 64 | 65 | 66 | 67 | UserID 68 | 69 | 70 | 71 | 72 | Username 73 | 74 | 75 | 76 | 77 | Type 78 | 79 | 80 | 81 | 82 | Expiry date 83 | 84 | 85 | 86 | 87 | Reason 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /src/gui/usercharacterdialog.cpp: -------------------------------------------------------------------------------- 1 | #include "usercharacterdialog.h" 2 | #include 3 | #include 4 | #include 5 | 6 | #include "gui.h" 7 | #include "interface/iuserdatabase.h" 8 | 9 | CUserCharacterDialog::CUserCharacterDialog(QWidget* parent, int userID) : QDialog(parent) 10 | { 11 | m_pUI = new Ui::UserCharacterDialog(); 12 | m_pUI->setupUi(this); 13 | 14 | setWindowFlags(windowFlags() | Qt::MSWindowsFixedSizeDialogHint); 15 | 16 | m_nUserID = userID; 17 | 18 | Init(); 19 | } 20 | 21 | void CUserCharacterDialog::Init() 22 | { 23 | CUserCharacter character; 24 | character.lowFlag = UFLAG_LOW_ALL; 25 | character.highFlag = UFLAG_LOW_ALL; 26 | if (g_pUserDatabase->GetCharacter(m_nUserID, character) <= 0) 27 | { 28 | QMessageBox::critical(this, "Error", "Failed to get user character"); 29 | close(); 30 | } 31 | 32 | CUserData data; 33 | data.flag = UDATA_FLAG_USERNAME | UDATA_FLAG_REGISTERTIME | UDATA_FLAG_LASTLOGONTIME | UDATA_FLAG_FIRSTLOGONTIME; 34 | if (g_pUserDatabase->GetUserData(m_nUserID, data) <= 0) 35 | { 36 | QMessageBox::critical(this, "Error", "Failed to get user data"); 37 | close(); 38 | } 39 | 40 | m_pUI->Username->setText(QString::fromStdString(data.userName)); 41 | m_pUI->Nickname->setText(QString::fromStdString(character.gameName)); 42 | m_pUI->Level->setText(QString::number(character.level)); 43 | m_pUI->Points->setText(QString::number(character.points)); 44 | m_pUI->Cash->setText(QString::number(character.cash)); 45 | m_pUI->ClanName->setText(QString::fromStdString(character.clanName)); 46 | m_pUI->RegisterDate->setText(QDateTime::fromSecsSinceEpoch(data.registerTime * 60).toString("yyyy-MM-dd hh:mm:ss")); 47 | m_pUI->LastLoginDate->setText(QDateTime::fromSecsSinceEpoch(data.lastLogonTime * 60).toString("yyyy-MM-dd hh:mm:ss")); 48 | m_pUI->FirstLoginDate->setText(QDateTime::fromSecsSinceEpoch(data.firstLogonTime * 60).toString("yyyy-MM-dd hh:mm:ss")); 49 | } 50 | 51 | CUserCharacterDialog::~CUserCharacterDialog() 52 | { 53 | delete m_pUI; 54 | } -------------------------------------------------------------------------------- /src/gui/usercharacterdialog.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace Ui 6 | { 7 | class UserCharacterDialog; 8 | } 9 | 10 | class CUserCharacterDialog : public QDialog 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | CUserCharacterDialog(QWidget* parent, int userID); 16 | ~CUserCharacterDialog(); 17 | 18 | private: 19 | void Init(); 20 | 21 | private: 22 | Ui::UserCharacterDialog* m_pUI; 23 | int m_nUserID; 24 | }; -------------------------------------------------------------------------------- /src/interface/ichannelmanager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "imanager.h" 4 | 5 | class IUser; 6 | 7 | class IChannelManager : public IBaseManager 8 | { 9 | public: 10 | virtual bool OnChannelListPacket(IExtendedSocket* socket) = 0; 11 | virtual bool OnRoomRequest(CReceivePacket* msg, IExtendedSocket* socket) = 0; 12 | virtual bool OnRoomListPacket(CReceivePacket* msg, IExtendedSocket* socket) = 0; 13 | virtual bool OnLobbyMessage(CReceivePacket* msg, IExtendedSocket* socket, IUser* user) = 0; 14 | virtual bool OnWhisperMessage(CReceivePacket* msg, IUser* user) = 0; 15 | virtual bool OnRoomUserMessage(CReceivePacket* msg, IUser* user) = 0; 16 | virtual bool OnRoomTeamUserMessage(CReceivePacket* msg, IUser* user) = 0; 17 | virtual bool OnServerYellMessage(CReceivePacket* msg, IUser* user) = 0; 18 | 19 | virtual class CChannelServer* GetServerByIndex(int index) = 0; 20 | virtual void JoinChannel(IUser* user, int channelServerID, int channelID, bool transfer) = 0; 21 | }; -------------------------------------------------------------------------------- /src/interface/iclanmanager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "imanager.h" 4 | 5 | class IUser; 6 | 7 | class IClanManager : public IBaseManager 8 | { 9 | public: 10 | virtual bool OnPacket(CReceivePacket* msg, IExtendedSocket* socket) = 0; 11 | virtual bool OnClanListRequest(CReceivePacket* msg, IUser* user) = 0; 12 | virtual bool OnClanInfoRequest(CReceivePacket* msg, IUser* user) = 0; 13 | virtual bool OnClanCreateRequest(CReceivePacket* msg, IUser* user) = 0; 14 | virtual bool OnClanJoinRequest(CReceivePacket* msg, IUser* user) = 0; 15 | virtual bool OnClanCancelJoinRequest(CReceivePacket* msg, IUser* user) = 0; 16 | virtual bool OnClanJoinApproveRequest(CReceivePacket* msg, IUser* user) = 0; 17 | virtual bool OnClanJoinResultRequest(CReceivePacket* msg, IUser* user) = 0; 18 | virtual bool OnClanLeaveRequest(CReceivePacket* msg, IUser* user) = 0; 19 | virtual bool OnClanInviteRequest(CReceivePacket* msg, IUser* user) = 0; 20 | virtual bool OnClanChangeMemberGradeRequest(CReceivePacket* msg, IUser* user) = 0; 21 | virtual bool OnClanKickMemberRequest(CReceivePacket* msg, IUser* user) = 0; 22 | virtual bool OnClanUpdateMarkRequest(CReceivePacket* msg, IUser* user) = 0; 23 | virtual bool OnClanUpdateConfigRequest(CReceivePacket* msg, IUser* user) = 0; 24 | virtual bool OnClanSetNoticeRequest(CReceivePacket* msg, IUser* user) = 0; 25 | virtual bool OnClanStorageGiveItemRequest(CReceivePacket* msg, IUser* user) = 0; 26 | virtual bool OnClanStorageGetItemRequest(CReceivePacket* msg, IUser* user) = 0; 27 | virtual bool OnClanStorageRequest(CReceivePacket* msg, IUser* user) = 0; 28 | virtual bool OnClanStorageDeleteItem(CReceivePacket* msg, IUser* user) = 0; 29 | virtual bool OnClanDissolveRequest(CReceivePacket* msg, IUser* user) = 0; 30 | virtual bool OnClanDelegateMasterRequest(CReceivePacket* msg, IUser* user) = 0; 31 | virtual bool OnClanMemberUserListRequest(CReceivePacket* msg, IUser* user) = 0; 32 | virtual bool OnClanJoinUserListRequest(CReceivePacket* msg, IUser* user) = 0; 33 | virtual bool OnClanChatMessage(CReceivePacket* msg, IUser* user) = 0; 34 | 35 | virtual void OnUserLogin(IUser* user) = 0; 36 | }; 37 | -------------------------------------------------------------------------------- /src/interface/idedicatedservermanager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "imanager.h" 4 | 5 | class CDedicatedServer; 6 | class IRoom; 7 | class IDedicatedServerManager : public IBaseManager 8 | { 9 | public: 10 | virtual bool OnPacket(CReceivePacket* msg, IExtendedSocket* socket) = 0; 11 | 12 | virtual void AddServer(IExtendedSocket* socket, int ip, int port) = 0; 13 | 14 | virtual CDedicatedServer* GetAvailableServerFromPools(IRoom* room) = 0; 15 | virtual bool IsPoolAvailable() = 0; 16 | virtual CDedicatedServer* GetServerBySocket(IExtendedSocket* socket) = 0; 17 | virtual void RemoveServer(IExtendedSocket* socket) = 0; 18 | virtual void TransferServer(IExtendedSocket* socket, const std::string& ipAddress, int port) = 0; 19 | }; -------------------------------------------------------------------------------- /src/interface/ievent.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | enum class EventFunctionType 8 | { 9 | NotSpecified = 0, 10 | TCPPacket = 1, 11 | }; 12 | 13 | class IEvent 14 | { 15 | public: 16 | virtual void Execute() = 0; 17 | virtual EventFunctionType GetType() = 0; 18 | }; 19 | 20 | class IExtendedSocket; 21 | class CReceivePacket; 22 | 23 | class IEvents 24 | { 25 | public: 26 | virtual void AddEvent(IEvent* ev) = 0; 27 | virtual void AddEventFunction(const std::function& func) = 0; 28 | }; 29 | -------------------------------------------------------------------------------- /src/interface/ihostmanager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "imanager.h" 4 | 5 | class IUser; 6 | class CGameMatch; 7 | 8 | class IHostManager : public IBaseManager 9 | { 10 | public: 11 | virtual bool OnPacket(CReceivePacket* msg, IExtendedSocket* socket) = 0; 12 | virtual void OnHostChanged(IUser* gameMatchUser, IUser* newHost, CGameMatch* match) = 0; 13 | }; -------------------------------------------------------------------------------- /src/interface/iitemmanager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "imanager.h" 4 | 5 | class IExtendedSocket; 6 | class IUser; 7 | class CUserInventoryItem; 8 | struct RewardItem; 9 | struct RewardNotice; 10 | struct Reward; 11 | struct WeaponPaint; 12 | 13 | class IItemManager : public IBaseManager 14 | { 15 | public: 16 | virtual bool LoadRewards() = 0; 17 | virtual bool LoadWeaponPaints() = 0; 18 | virtual bool KVToJson() = 0; 19 | virtual bool OnItemPacket(CReceivePacket* msg, IExtendedSocket* socket) = 0; 20 | virtual int AddItem(int userID, IUser* user, int itemId, int count, int duration, int lockStatus = 0) = 0; 21 | virtual int AddItems(int userID, IUser* user, std::vector& item) = 0; 22 | virtual bool RemoveItem(int userID, IUser* user, CUserInventoryItem& item) = 0; 23 | virtual int UseItem(IUser* user, int slot, int additionalArg = 0, int additionalArg2 = 0) = 0; 24 | virtual bool CanUseItem(const CUserInventoryItem& item) = 0; 25 | virtual bool OpenDecoder(IUser* user, int count, int slot) = 0; 26 | virtual int ExtendItem(int userID, IUser* user, CUserInventoryItem& item, int newExpiryDate, bool duration = false) = 0; 27 | virtual bool OnDisassembleRequest(IUser* user, CReceivePacket* msg) = 0; 28 | virtual RewardNotice GiveReward(int userID, IUser* user, int rewardID, int rewardSelectID = 0, bool ignoreClient = false, int randomRepeatCount = 0) = 0; 29 | 30 | virtual void OnUserLogin(IUser* user) = 0; 31 | virtual void OnNicknameChangeUse(IUser* user, std::string newNickname) = 0; 32 | virtual void OnRewardSelect(CReceivePacket* msg, IUser* user) = 0; 33 | virtual void OnCostumeEquip(IUser* user, int slot) = 0; 34 | virtual bool OnItemUse(IUser* user, CUserInventoryItem& item, int count = 1) = 0; 35 | 36 | virtual Reward* GetRewardByID(int rewardID) = 0; 37 | virtual std::vector GetWeaponPaints() = 0; 38 | }; -------------------------------------------------------------------------------- /src/interface/iluckyitemmanager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "imanager.h" 4 | 5 | class IUser; 6 | struct ItemBox; 7 | struct ItemBoxItem; 8 | 9 | class ILuckyItemManager : public IBaseManager 10 | { 11 | public: 12 | virtual void LoadLuckyItems() = 0; 13 | virtual bool KVToJson() = 0; // TODO: delete sometime 14 | virtual int OpenItemBox(IUser* user, int itemBox, int itemBoxOpenCount) = 0; 15 | virtual std::vector& GetItemBoxes() = 0; 16 | virtual std::vector& GetItems() = 0; 17 | virtual ItemBox* GetItemBoxByItemId(int itemId) = 0; 18 | }; 19 | -------------------------------------------------------------------------------- /src/interface/imanager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class IBaseManager 6 | { 7 | public: 8 | virtual bool Init() = 0; 9 | virtual void Shutdown() = 0; 10 | virtual bool CanReload() = 0; 11 | virtual std::string GetName() = 0; 12 | virtual void OnSecondTick(time_t curTime) = 0; 13 | virtual void OnMinuteTick(time_t curTime) = 0; 14 | virtual bool ShouldDoSecondTick() = 0; 15 | virtual bool ShouldDoMinuteTick() = 0; 16 | }; 17 | 18 | class IManager 19 | { 20 | public: 21 | virtual bool InitAll() = 0; 22 | virtual void ShutdownAll() = 0; 23 | virtual bool ReloadAll() = 0; 24 | virtual void AddManager(IBaseManager* pElem) = 0; 25 | virtual void RemoveManager(IBaseManager* pElem) = 0; 26 | virtual IBaseManager* GetManager(const std::string& name) = 0; 27 | virtual void SecondTick(time_t curTime) = 0; 28 | virtual void MinuteTick(time_t curTime) = 0; 29 | }; -------------------------------------------------------------------------------- /src/interface/iminigamemanager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "imanager.h" 4 | 5 | class IUser; 6 | 7 | class IMiniGameManager : public IBaseManager 8 | { 9 | public: 10 | virtual void OnPacket(CReceivePacket* msg, IExtendedSocket* socket) = 0; 11 | virtual void WeaponReleaseAddCharacter(IUser* user, char charID, int count) = 0; 12 | virtual void SendWeaponReleaseUpdate(IUser* user) = 0; 13 | virtual void OnBingoUpdateRequest(IUser* user) = 0; 14 | }; 15 | -------------------------------------------------------------------------------- /src/interface/iquestmanager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "imanager.h" 4 | 5 | #include 6 | 7 | class IExtendedSocket; 8 | class CReceivePacket; 9 | class CGameMatch; 10 | class CGameMatchUserStat; 11 | class IUser; 12 | class CQuest; 13 | class CQuestTask; 14 | class CQuestEvent; 15 | class CQuestEventTask; 16 | struct UserQuestProgress; 17 | struct UserQuestTaskProgress; 18 | struct GameMatch_KillEvent; 19 | struct QuestReward_s; 20 | 21 | class IQuestManager : public IBaseManager 22 | { 23 | public: 24 | virtual void LoadQuests() = 0; 25 | virtual void LoadEventQuests() = 0; 26 | virtual void LoadClanQuests() = 0; 27 | virtual std::vector& GetQuests() = 0; 28 | virtual void OnPacket(CReceivePacket* msg, IExtendedSocket* socket) = 0; 29 | virtual void OnTitlePacket(CReceivePacket* msg, IExtendedSocket* socket) = 0; 30 | 31 | virtual void OnMatchMinuteTick(CGameMatchUserStat* userStat, CGameMatch* gameMatch) = 0; 32 | 33 | // ingame events 34 | virtual void OnKillEvent(CGameMatchUserStat* userStat, CGameMatch* gameMatch, GameMatch_KillEvent& killEvent) = 0; 35 | virtual void OnBombExplode(CGameMatchUserStat* userStat, CGameMatch* gameMatch) = 0; 36 | virtual void OnBombDefuse(CGameMatchUserStat* userStat, CGameMatch* gameMatch) = 0; 37 | virtual void OnHostageEscape(CGameMatchUserStat* userStat, CGameMatch* gameMatch) = 0; 38 | virtual void OnMonsterKill(CGameMatchUserStat* userStat, CGameMatch* gameMatch, int monsterType) = 0; 39 | virtual void OnMosquitoKill(CGameMatchUserStat* userStat, CGameMatch* gameMatch) = 0; 40 | virtual void OnKiteKill(CGameMatchUserStat* userStat, CGameMatch* gameMatch) = 0; 41 | 42 | virtual void OnLevelUpEvent(IUser* user, int level, int newLevel) = 0; 43 | virtual void OnMatchEndEvent(CGameMatchUserStat* userStat, CGameMatch* gameMatch, int userTeam) = 0; 44 | virtual void OnGameMatchLeave(IUser* user, std::vector& questProgress, std::vector& questsEventsProgress) = 0; 45 | virtual void OnUserLogin(IUser* user) = 0; 46 | 47 | virtual void OnQuestTaskFinished(IUser* user, UserQuestTaskProgress& taskProgress, CQuestTask* task, CQuest* quest) = 0; 48 | virtual void OnQuestEventTaskFinished(IUser* user, UserQuestTaskProgress& taskProgress, CQuestEventTask* task, CQuestEvent* quest) = 0; 49 | virtual void OnQuestFinished(IUser* user, CQuest* quest, UserQuestProgress& questProgress) = 0; 50 | virtual void OnReceiveReward(IUser* user, int rewardID, int questID) = 0; 51 | virtual void OnSpecialMissionRequest(IUser* user, CReceivePacket* msg) = 0; 52 | virtual void OnSetFavouriteRequest(IUser* user, CReceivePacket* msg) = 0; 53 | virtual void OnTitleSetPrefixRequest(IUser* user, CReceivePacket* msg) = 0; 54 | virtual void OnTitleListSetRequest(IUser* user, CReceivePacket* msg) = 0; 55 | virtual void OnTitleListRemoveRequest(IUser* user, CReceivePacket* msg) = 0; 56 | 57 | virtual CQuest* GetQuest(int questID) = 0; 58 | virtual CQuestEvent* GetEventQuest(int questID) = 0; 59 | virtual QuestReward_s GetQuestReward(CQuest* quest, int rewardID) = 0; 60 | virtual UserQuestProgress GetUserQuestProgress(CQuest* quest, int userID) = 0; 61 | virtual UserQuestTaskProgress GetUserQuestTaskProgress(CQuest* quest, int userID, int taskID) = 0; 62 | }; -------------------------------------------------------------------------------- /src/interface/irankmanager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "imanager.h" 4 | 5 | class IUser; 6 | 7 | class IRankManager : public IBaseManager 8 | { 9 | public: 10 | virtual bool OnRankPacket(CReceivePacket* msg, IExtendedSocket* socket) = 0; 11 | }; -------------------------------------------------------------------------------- /src/interface/iroom.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class IUser; 7 | class CGameMatch; 8 | class CDedicatedServer; 9 | class CReceivePacket; 10 | class CRoomSettings; 11 | class CChannel; 12 | class CRoomUser; 13 | enum RoomStatus; 14 | enum RoomTeamNum; 15 | enum RoomReadyStatus; 16 | 17 | class IRoom 18 | { 19 | public: 20 | virtual ~IRoom() {} 21 | 22 | virtual void Shutdown() = 0; 23 | 24 | virtual int GetNumOfPlayers() = 0; 25 | virtual int GetFreeSlots() = 0; 26 | virtual bool HasFreeSlots() = 0; 27 | virtual bool HasPassword() = 0; 28 | virtual bool HasUser(IUser* user) = 0; 29 | virtual void AddUser(IUser* user) = 0; 30 | virtual RoomTeamNum FindDesirableTeamNum() = 0; 31 | virtual RoomTeamNum GetUserTeam(IUser* user) = 0; 32 | virtual int GetNumOfReadyRealPlayers() = 0; 33 | virtual int GetNumOfRealCts() = 0; 34 | virtual int GetNumOfRealTerrorists() = 0; 35 | virtual int GetNumOfReadyPlayers() = 0; 36 | virtual RoomReadyStatus IsUserReady(IUser* user) = 0; 37 | virtual bool IsRoomReady() = 0; 38 | virtual void SetUserIngame(IUser* user, bool inGame) = 0; 39 | virtual void RemoveUser(IUser* targetUser) = 0; 40 | //virtual void RemoveUserById(int userId) = 0; 41 | virtual void SetUserToTeam(IUser* user, RoomTeamNum newTeam) = 0; 42 | virtual RoomStatus GetStatus() = 0; 43 | virtual void SetStatus(RoomStatus newStatus) = 0; 44 | virtual RoomReadyStatus ToggleUserReadyStatus(IUser* user) = 0; 45 | virtual void ResetStatusIngameUsers() = 0; 46 | //virtual bool CanStartGame() = 0; 47 | virtual void OnUserRemoved(IUser* user) = 0; 48 | virtual void SendRemovedUser(IUser* deletedUser) = 0; 49 | virtual void UpdateHost(IUser* newHost) = 0; 50 | virtual void HostStartGame() = 0; 51 | virtual void UserGameJoin(IUser* user) = 0; 52 | virtual void EndGame(bool forcedEnd) = 0; 53 | virtual bool FindAndUpdateNewHost() = 0; 54 | virtual void UpdateSettings(CRoomSettings& newSettings) = 0; 55 | virtual void OnUserMessage(CReceivePacket* msg, IUser* user) = 0; 56 | virtual void OnUserTeamMessage(CReceivePacket* msg, IUser* user) = 0; 57 | virtual void OnGameStart() = 0; 58 | virtual void AddKickedUser(IUser* user) = 0; 59 | virtual void ClearKickedUsers() = 0; 60 | virtual void KickUser(IUser* user) = 0; 61 | virtual void VoteKick(IUser* user, bool kick) = 0; 62 | virtual void SendJoinNewRoom(IUser* user) = 0; 63 | virtual void SendRoomSettings(IUser* user) = 0; 64 | virtual void SendUpdateRoomSettings(IUser* user, CRoomSettings* settings, int lowFlag, int lowMidFlag, int highMidFlag, int highFlag) = 0; 65 | virtual void SendRoomUsersReadyStatus(IUser* user) = 0; 66 | virtual void SendReadyStatusToAll() = 0; 67 | virtual void SendReadyStatusToAll(IUser* user) = 0; 68 | virtual void SendNewUser(IUser* user, IUser* newUser) = 0; 69 | virtual void SendUserReadyStatus(IUser* user, IUser* player) = 0; 70 | virtual void SendConnectHost(IUser* user, IUser* host) = 0; 71 | virtual void SendStartMatch(IUser* host) = 0; 72 | virtual void SendCloseResultWindow(IUser* user) = 0; 73 | virtual void SendTeamChange(IUser* user, IUser* player, RoomTeamNum newTeamNum) = 0; 74 | virtual void SendGameEnd(IUser* user) = 0; 75 | virtual void SendRoomStatus(IUser* user) = 0; 76 | virtual void SendPlayerLeaveIngame(IUser* user) = 0; 77 | 78 | virtual int GetID() = 0; 79 | virtual IUser* GetHostUser() = 0; 80 | virtual std::vector GetUsers() = 0; 81 | virtual CRoomSettings* GetSettings() = 0; 82 | virtual CGameMatch* GetGameMatch() = 0; 83 | virtual CChannel* GetParentChannel() = 0; 84 | virtual bool IsUserKicked(int userID) = 0; 85 | 86 | virtual CDedicatedServer* GetServer() = 0; 87 | virtual void SetServer(CDedicatedServer* server) = 0; 88 | virtual void ChangeMap(int mapId) = 0; 89 | 90 | virtual bool IsUserInFamilyBattleUsers(int userId) = 0; 91 | }; -------------------------------------------------------------------------------- /src/interface/iserverinstance.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class CReceivePacket; 7 | class IExtendedSocket; 8 | 9 | class IServerInstance 10 | { 11 | public: 12 | virtual bool Reload() = 0; 13 | virtual time_t GetCurrentTime() = 0; 14 | virtual tm* GetCurrentLocalTime() = 0; 15 | virtual double GetMemoryInfo() = 0; 16 | virtual const char* GetMainInfo() = 0; 17 | virtual void DisconnectClient(IExtendedSocket* socket) = 0; 18 | virtual std::vector GetClients() = 0; 19 | virtual IExtendedSocket* GetSocketByID(unsigned int id) = 0; 20 | 21 | virtual void OnCommand(const std::string& command) = 0; 22 | }; -------------------------------------------------------------------------------- /src/interface/ishopmanager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "imanager.h" 4 | 5 | class CReceivePacket; 6 | class IExtendedSocket; 7 | struct Product; 8 | struct SubProduct; 9 | class IUser; 10 | 11 | class IShopManager : public IBaseManager 12 | { 13 | public: 14 | virtual bool LoadProducts() = 0; 15 | 16 | virtual void OnShopPacket(CReceivePacket* msg, IExtendedSocket* socket) = 0; 17 | virtual void GetProductBySubId(int productId, Product& product, SubProduct& subProduct) = 0; 18 | virtual bool BuyProduct(IUser* user, int productTypeId, int productId) = 0; 19 | 20 | virtual const std::vector& GetProducts() = 0; 21 | virtual const std::vector>& GetRecommendedProducts() = 0; 22 | virtual const std::vector& GetPopularProducts() = 0; 23 | }; 24 | -------------------------------------------------------------------------------- /src/interface/iuser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | enum UserStatus; 7 | class IExtendedSocket; 8 | class IRoom; 9 | class CRoomUser; 10 | struct UserNetworkConfig_s; 11 | class CChannel; 12 | class CChannelServer; 13 | class CUserData; 14 | class CUserCharacter; 15 | class CUserCharacterExtended; 16 | 17 | struct UserData 18 | { 19 | int m_nID; 20 | std::string m_UserName; 21 | UserStatus m_Status; 22 | int m_nUptime; 23 | int m_nCurrentChannelID; 24 | int m_nCurrentRoomID; 25 | }; 26 | 27 | class IUser 28 | { 29 | public: 30 | virtual ~IUser() {} 31 | 32 | virtual void SetCurrentChannel(CChannel* channel) = 0; 33 | virtual void SetLastChannelServer(CChannelServer* channelServer) = 0; 34 | virtual void SetStatus(UserStatus newStatus) = 0; 35 | virtual void SetCurrentRoom(IRoom* room) = 0; 36 | virtual void SetRoomData(CRoomUser* roomUser) = 0; 37 | 38 | virtual UserNetworkConfig_s GetNetworkConfig() = 0; 39 | virtual IExtendedSocket* GetExtendedSocket() = 0; 40 | virtual CChannel* GetCurrentChannel() = 0; 41 | virtual CChannelServer* GetLastChannelServer() = 0; 42 | virtual IRoom* GetCurrentRoom() = 0; 43 | virtual CRoomUser* GetRoomData() = 0; 44 | virtual UserStatus GetStatus() = 0; 45 | virtual bool IsPlaying() = 0; 46 | virtual int GetUptime() = 0; 47 | virtual int GetID() = 0; 48 | virtual std::string GetUsername() = 0; 49 | virtual const char* GetLogName() = 0; 50 | virtual CUserData GetUser(int flag) = 0; 51 | virtual CUserCharacter GetCharacter(int lowFlag, int highFlag = 0) = 0; 52 | virtual CUserCharacterExtended GetCharacterExtended(int flag) = 0; 53 | 54 | virtual int UpdateHolepunch(int portId, const std::string& localIpAddress, int localPort, int externalPort) = 0; 55 | virtual void UpdateClientUserInfo(CUserCharacter character) = 0; 56 | virtual void UpdateGameName(const std::string& gameName) = 0; 57 | virtual int UpdatePoints(int64_t points) = 0; 58 | virtual void UpdateCash(int64_t cash) = 0; 59 | virtual void UpdateHonorPoints(int honorPoints) = 0; 60 | virtual void UpdatePrefix(int prefixID) = 0; 61 | virtual void UpdateStat(int battles, int win, int kills, int deaths) = 0; 62 | virtual void UpdateLocation(int nation, int city, int town) = 0; 63 | virtual void UpdateChatColor(int chatColorID) = 0; 64 | virtual void UpdateRank(int leagueID) = 0; 65 | virtual void UpdateLevel(int level) = 0; 66 | virtual void UpdateExp(int64_t exp) = 0; 67 | virtual int UpdatePasswordBoxes(int passwordBoxes) = 0; 68 | virtual void UpdateTitles(int slot, int titleID) = 0; 69 | virtual void UpdateAchievementList(int titleID) = 0; 70 | virtual void UpdateClan(int clanID) = 0; 71 | virtual void UpdateTournament(int tournament) = 0; 72 | virtual int UpdateBanList(const std::string& gameName, bool remove = false) = 0; 73 | virtual void UpdateBanSettings(int settings) = 0; 74 | virtual void UpdateNameplate(int nameplateID) = 0; 75 | virtual void UpdateZbRespawnEffect(int zbRespawnEffect) = 0; 76 | virtual void UpdateKillerMarkEffect(int killerMarkEffect) = 0; 77 | 78 | virtual int CheckForLvlUp(int64_t exp) = 0; 79 | 80 | virtual void OnTick() = 0; 81 | 82 | virtual bool IsCharacterExists() = 0; 83 | virtual bool CreateCharacter(const std::string& gameName) = 0; 84 | }; -------------------------------------------------------------------------------- /src/interface/iusermanager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "imanager.h" 4 | #include "iuser.h" 5 | 6 | #include 7 | #include 8 | 9 | class CUserInventoryItem; 10 | class CReceivePacket; 11 | class IExtendedSocket; 12 | class IUser; 13 | 14 | class IUserManager : public IBaseManager 15 | { 16 | public: 17 | virtual bool LoadZombieWarWeaponList() = 0; 18 | virtual bool LoadRandomWeaponList() = 0; 19 | virtual bool OnLoginPacket(CReceivePacket* msg, IExtendedSocket* socket) = 0; 20 | virtual bool OnUdpPacket(CReceivePacket* msg, IExtendedSocket* socket) = 0; 21 | virtual bool OnOptionPacket(CReceivePacket* msg, IExtendedSocket* socket) = 0; 22 | virtual bool OnVersionPacket(CReceivePacket* msg, IExtendedSocket* socket) = 0; 23 | virtual bool OnFavoritePacket(CReceivePacket* msg, IExtendedSocket* socket) = 0; 24 | virtual bool OnCharacterPacket(CReceivePacket* msg, IExtendedSocket* socket) = 0; 25 | virtual bool OnUserMessage(CReceivePacket* msg, IExtendedSocket* socket) = 0; 26 | virtual bool OnUpdateInfoPacket(CReceivePacket* msg, IExtendedSocket* socket) = 0; 27 | virtual bool OnReportPacket(CReceivePacket* msg, IExtendedSocket* socket) = 0; 28 | virtual bool OnAlarmPacket(CReceivePacket* msg, IExtendedSocket* socket) = 0; 29 | virtual bool OnUserSurveyPacket(CReceivePacket* msg, IExtendedSocket* socket) = 0; 30 | virtual bool OnBanPacket(CReceivePacket* msg, IExtendedSocket* socket) = 0; 31 | virtual bool OnMessengerPacket(CReceivePacket* msg, IExtendedSocket* socket) = 0; 32 | virtual bool OnAddonPacket(CReceivePacket* msg, IExtendedSocket* socket) = 0; 33 | virtual bool OnLeaguePacket(CReceivePacket* msg, IExtendedSocket* socket) = 0; 34 | virtual bool OnCryptPacket(CReceivePacket* msg, IExtendedSocket* socket) = 0; 35 | virtual bool OnKickPacket(CReceivePacket* msg, IExtendedSocket* socket) = 0; 36 | 37 | virtual void SendNoticeMessageToAll(const std::string& msg) = 0; 38 | virtual void SendNoticeMsgBoxToAll(const std::string& msg) = 0; 39 | 40 | virtual int LoginUser(IExtendedSocket* socket, const std::string& userName, const std::string& password) = 0; 41 | virtual int RegisterUser(IExtendedSocket* socket, const std::string& userName, const std::string& password) = 0; 42 | virtual void DisconnectUser(IUser* user) = 0; 43 | virtual void DisconnectAllFromServer() = 0; 44 | virtual IUser* AddUser(IExtendedSocket* socket, int userID, const std::string& userName) = 0; 45 | virtual IUser* GetUserById(int userID) = 0; 46 | virtual IUser* GetUserBySocket(IExtendedSocket* socket) = 0; 47 | virtual IUser* GetUserByUsername(const std::string& userName) = 0; 48 | virtual IUser* GetUserByNickname(const std::string& nickname) = 0; 49 | virtual void RemoveUser(IUser* user) = 0; 50 | virtual void RemoveUserById(int userID) = 0; 51 | virtual void RemoveUserBySocket(IExtendedSocket* socket) = 0; 52 | virtual void CleanUpUser(IUser* user) = 0; 53 | 54 | virtual std::vector GetUsers() = 0; 55 | 56 | virtual int ChangeUserNickname(IUser* user, const std::string& newNickname, bool createCharacter = false) = 0; 57 | 58 | virtual std::vector& GetDefaultInventoryItems() = 0; 59 | 60 | virtual void SendMetadata(IExtendedSocket* socket) = 0; 61 | virtual void SendCrypt(IExtendedSocket* socket) = 0; 62 | }; 63 | -------------------------------------------------------------------------------- /src/interface/ivoxelmanager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "imanager.h" 4 | 5 | class IVoxelManager : public IBaseManager 6 | { 7 | public: 8 | virtual bool OnPacket(CReceivePacket* msg, IExtendedSocket* socket) = 0; 9 | virtual std::string GetSlotDetails(const std::string& slotId) = 0; 10 | }; -------------------------------------------------------------------------------- /src/interface/net/iextendedsocket.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef WIN32 4 | #include "Windows.h" 5 | #else 6 | typedef int SOCKET; 7 | #endif 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | struct GuestData_s; 15 | class CSendPacket; 16 | class CReceivePacket; 17 | 18 | class IExtendedSocket 19 | { 20 | public: 21 | virtual ~IExtendedSocket() {} 22 | 23 | virtual bool SetupCrypt() = 0; 24 | virtual void SetCryptInput(bool val) = 0; 25 | virtual void SetCryptOutput(bool val) = 0; 26 | virtual unsigned char* GetCryptKey() = 0; 27 | virtual unsigned char* GetCryptIV() = 0; 28 | virtual WOLFSSL*& GetSSLObject() = 0; 29 | virtual void SetSSLObject(WOLFSSL* ssl) = 0; 30 | virtual void SetIP(const std::string& addr) = 0; 31 | virtual void SetHWID(const std::vector& hwid) = 0; 32 | virtual const std::string& GetIP() = 0; 33 | virtual const std::vector& GetHWID() = 0; 34 | virtual int GetSeq() = 0; 35 | virtual int LoggerGetSeq() = 0; 36 | virtual void ResetSeq() = 0; 37 | virtual CReceivePacket* Read() = 0; 38 | virtual int Send(std::vector& buffer, bool serverHelloMsg = false) = 0; 39 | virtual int Send(CSendPacket* msg, bool forceSend = false) = 0; 40 | 41 | virtual unsigned int GetID() = 0; 42 | virtual SOCKET GetSocket() = 0; 43 | virtual void SetMsg(CReceivePacket* msg) = 0; 44 | virtual CReceivePacket* GetMsg() = 0; 45 | virtual int GetReadResult() = 0; 46 | virtual int GetBytesReceived() = 0; 47 | virtual int GetBytesSent() = 0; 48 | virtual std::vector& GetPacketsToSend() = 0; 49 | virtual GuestData_s& GetGuestData() = 0; 50 | }; 51 | -------------------------------------------------------------------------------- /src/interface/net/iserverlistener.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "common/buffer.h" 4 | 5 | class CReceivePacket; 6 | class IExtendedSocket; 7 | 8 | class IServerListenerTCP 9 | { 10 | public: 11 | virtual bool OnTCPConnectionCreated(IExtendedSocket* socket) = 0; 12 | virtual void OnTCPConnectionClosed(IExtendedSocket* socket) = 0; 13 | virtual void OnTCPMessage(IExtendedSocket* socket, CReceivePacket* msg) = 0; 14 | virtual void OnTCPError(int errorCode) = 0; 15 | }; 16 | 17 | class IServerListenerUDP 18 | { 19 | public: 20 | virtual void OnUDPMessage(Buffer& buf, unsigned short port) = 0; 21 | virtual void OnUDPError(int errorCode) = 0; 22 | }; 23 | 24 | class IClientListenerTCP 25 | { 26 | public: 27 | virtual void OnTCPServerConnected() = 0; 28 | virtual void OnTCPServerConnectFailed() = 0; 29 | virtual void OnTCPMessage(CReceivePacket* msg) = 0; 30 | virtual void OnTCPError(int errorCode) = 0; 31 | }; -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #ifdef WIN32 3 | #include "crashdump.h" 4 | #endif 5 | #ifdef USE_GUI 6 | #include "gui/igui.h" 7 | #endif 8 | #include "manager/manager.h" 9 | #include "common/utils.h" 10 | 11 | CServerInstance* g_pServerInstance; 12 | 13 | CEvents g_Events; 14 | CCriticalSection g_ServerCriticalSection; 15 | 16 | #ifdef WIN32 17 | void invalid_parameter_function(const wchar_t* expression, const wchar_t* function, const wchar_t* file, unsigned int line, uintptr_t pReserved) 18 | { 19 | printf("invalid_parameter_function called\n"); 20 | 21 | Logger().Info(OBFUSCATE("%ls, %ls, %ls, %d, %p\n"), expression, function, file, line, pReserved); 22 | } 23 | 24 | BOOL WINAPI CtrlHandler(DWORD ctrlType) 25 | { 26 | if (ctrlType == CTRL_CLOSE_EVENT) 27 | { 28 | g_pServerInstance->SetServerActive(false); 29 | 30 | ExitThread(0); // hack to ignore close event 31 | return TRUE; 32 | } 33 | 34 | return FALSE; 35 | } 36 | #endif 37 | 38 | #ifdef USE_GUI 39 | CObjectSync g_GUIInitEvent; 40 | 41 | /** 42 | * Thread to run GUI. When GUI shuts down, it shuts down the server. 43 | */ 44 | void* GUIThread(void*) 45 | { 46 | if (!GUI()->Init(&Manager(), &g_Events)) 47 | { 48 | printf("error!\n"); 49 | } 50 | 51 | g_GUIInitEvent.Signal(); 52 | 53 | GUI()->Exec(); 54 | GUI()->Shutdown(); 55 | 56 | // shutdown the server after closing gui 57 | g_ServerCriticalSection.Enter(); 58 | 59 | g_pServerInstance->SetServerActive(false); 60 | 61 | g_ServerCriticalSection.Leave(); 62 | 63 | return NULL; 64 | } 65 | #endif 66 | 67 | int main(int argc, char* argv[]) 68 | { 69 | #ifdef WIN32 70 | SetUnhandledExceptionFilter(ExceptionFilter); 71 | _set_invalid_parameter_handler(invalid_parameter_function); 72 | SetConsoleCtrlHandler(CtrlHandler, TRUE); 73 | 74 | #ifdef USE_GUI 75 | // hide console when using gui 76 | ShowWindow(GetConsoleWindow(), SW_HIDE); 77 | #endif 78 | #endif 79 | 80 | #ifdef USE_GUI 81 | CThread qtThread(GUIThread); 82 | qtThread.Start(); 83 | 84 | // wait for gui init before we init the server 85 | g_GUIInitEvent.WaitForSignal(); 86 | 87 | AddLogger(new CGUILogger()); 88 | #endif 89 | AddLogger(new CFileLogger("Server")); 90 | 91 | g_pServerInstance = new CServerInstance(); 92 | if (!g_pServerInstance->Init()) 93 | { 94 | #ifdef USE_GUI 95 | qtThread.Join(); 96 | #endif 97 | delete g_pServerInstance; 98 | return 1; 99 | } 100 | 101 | #ifdef USE_GUI 102 | if (!GUI()->PostInit(g_pServerInstance)) 103 | { 104 | qtThread.Join(); 105 | delete g_pServerInstance; 106 | return 1; 107 | } 108 | 109 | GUI()->ShowMainWindow(); 110 | #endif 111 | 112 | CThread readConsoleThread(ReadConsoleThread); 113 | CThread eventThread(EventThread); 114 | readConsoleThread.Start(); 115 | eventThread.Start(); 116 | 117 | while (g_pServerInstance->IsServerActive()) 118 | { 119 | g_Events.AddEventFunction(std::bind(&CServerInstance::OnSecondTick, g_pServerInstance)); 120 | 121 | SleepMS(1000); 122 | } 123 | 124 | #ifdef USE_GUI 125 | GUI()->Exit(); 126 | qtThread.Join(); 127 | #endif 128 | 129 | eventThread.Join(); 130 | 131 | g_ServerCriticalSection.Enter(); 132 | 133 | // terminate read console thread because of std::getline (should be safe) 134 | readConsoleThread.Terminate(); 135 | 136 | g_ServerCriticalSection.Leave(); 137 | 138 | delete g_pServerInstance; 139 | 140 | return 0; 141 | } 142 | -------------------------------------------------------------------------------- /src/main.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "common/logger.h" 4 | 5 | #define NOMINMAX 6 | 7 | #ifdef _WIN32 8 | #include 9 | #include 10 | #include 11 | #else 12 | #include 13 | #include 14 | 15 | #define MAX_PATH 260 16 | 17 | #endif 18 | 19 | #include //std::string, std::cout 20 | #include //std::vector 21 | #include //std::map 22 | #include //std::operator+ 23 | #include //int definitions 24 | #include //time, localtime functions 25 | #include //signals... 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include "obfuscate.h" 35 | 36 | #include "serverinstance.h" 37 | #include "event.h" 38 | 39 | extern CEvents g_Events; 40 | extern CCriticalSection g_ServerCriticalSection; -------------------------------------------------------------------------------- /src/manager/channelmanager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "interface/ichannelmanager.h" 4 | #include "manager.h" 5 | 6 | #include "channel/channelserver.h" 7 | //#include "manager/usermanager.h" 8 | #include "user/user.h" 9 | 10 | class CChannelManager : public CBaseManager 11 | { 12 | public: 13 | CChannelManager(); 14 | ~CChannelManager(); 15 | 16 | virtual bool Init(); 17 | virtual void Shutdown(); 18 | 19 | bool OnChannelListPacket(IExtendedSocket* socket); 20 | bool OnRoomRequest(CReceivePacket* msg, IExtendedSocket* socket); 21 | bool OnRoomListPacket(CReceivePacket* msg, IExtendedSocket* socket); 22 | bool OnLobbyMessage(CReceivePacket* msg, IExtendedSocket* socket, IUser* user); 23 | bool OnWhisperMessage(CReceivePacket* msg, IUser* user); 24 | bool OnRoomUserMessage(CReceivePacket* msg, IUser* user); 25 | bool OnRoomTeamUserMessage(CReceivePacket* msg, IUser* user); 26 | bool OnServerYellMessage(CReceivePacket* msg, IUser* user); 27 | 28 | class CChannelServer* GetServerByIndex(int index); 29 | void JoinChannel(IUser* user, int channelServerID, int channelID, bool transfer); 30 | void EndAllGames(); 31 | 32 | std::vector channelServers; 33 | 34 | private: 35 | bool OnCommandHandler(IExtendedSocket* socket, IUser* user, const std::string& message); 36 | 37 | bool OnNewRoomRequest(CReceivePacket* msg, IUser* user); 38 | bool OnJoinRoomRequest(CReceivePacket* msg, IUser* user); 39 | bool OnLeaveRoomRequest(IUser* user); 40 | bool OnToggleReadyRequest(IUser* user); 41 | bool OnConnectionFailure(IUser* user); 42 | bool OnGameStartRequest(IUser* user); 43 | bool OnCloseResultRequest(IUser* user); 44 | bool OnRoomUpdateSettings(CReceivePacket* msg, IUser* user); 45 | bool OnSetTeamRequest(CReceivePacket* msg, IUser* user); 46 | bool OnUserInviteRequest(CReceivePacket* msg, IUser* user); 47 | bool OnRoomSetZBAddonRequest(CReceivePacket* msg, IUser* user); 48 | bool OnRoomKickRequest(CReceivePacket* msg, IUser* user); 49 | bool OnRoomKickClanRequest(CReceivePacket* msg, IUser* user); 50 | bool OnRoomNoticeClanRequest(CReceivePacket* msg, IUser* user); 51 | bool OnVoxelRoomListRequest(CReceivePacket* msg, IUser* user); 52 | }; 53 | 54 | extern CChannelManager g_ChannelManager; -------------------------------------------------------------------------------- /src/manager/clanmanager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "interface/iclanmanager.h" 4 | #include "manager.h" 5 | 6 | class CClanManager : public CBaseManager 7 | { 8 | public: 9 | CClanManager(); 10 | ~CClanManager(); 11 | 12 | bool OnPacket(CReceivePacket* msg, IExtendedSocket* socket); 13 | bool OnClanListRequest(CReceivePacket* msg, IUser* user); 14 | bool OnClanInfoRequest(CReceivePacket* msg, IUser* user); 15 | bool OnClanCreateRequest(CReceivePacket* msg, IUser* user); 16 | bool OnClanJoinRequest(CReceivePacket* msg, IUser* user); 17 | bool OnClanCancelJoinRequest(CReceivePacket* msg, IUser* user); 18 | bool OnClanJoinApproveRequest(CReceivePacket* msg, IUser* user); 19 | bool OnClanJoinResultRequest(CReceivePacket* msg, IUser* user); 20 | bool OnClanLeaveRequest(CReceivePacket* msg, IUser* user); 21 | bool OnClanInviteRequest(CReceivePacket* msg, IUser* user); 22 | bool OnClanChangeMemberGradeRequest(CReceivePacket* msg, IUser* user); 23 | bool OnClanKickMemberRequest(CReceivePacket* msg, IUser* user); 24 | bool OnClanUpdateMarkRequest(CReceivePacket* msg, IUser* user); 25 | bool OnClanUpdateConfigRequest(CReceivePacket* msg, IUser* user); 26 | bool OnClanSetNoticeRequest(CReceivePacket* msg, IUser* user); 27 | bool OnClanStorageGiveItemRequest(CReceivePacket* msg, IUser* user); 28 | bool OnClanStorageGetItemRequest(CReceivePacket* msg, IUser* user); 29 | bool OnClanStorageRequest(CReceivePacket* msg, IUser* user); 30 | bool OnClanStorageDeleteItem(CReceivePacket* msg, IUser* user); 31 | bool OnClanDissolveRequest(CReceivePacket* msg, IUser* user); 32 | bool OnClanDelegateMasterRequest(CReceivePacket* msg, IUser* user); 33 | bool OnClanMemberUserListRequest(CReceivePacket* msg, IUser* user); 34 | bool OnClanJoinUserListRequest(CReceivePacket* msg, IUser* user); 35 | bool OnClanChatMessage(CReceivePacket* msg, IUser* user); 36 | 37 | void OnUserLogin(IUser* user); 38 | }; 39 | 40 | extern CClanManager g_ClanManager; -------------------------------------------------------------------------------- /src/manager/dedicatedservermanager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "manager.h" 4 | #include "interface/idedicatedservermanager.h" 5 | 6 | class IRoom; 7 | class IExtendedSocket; 8 | class CReceivePacket; 9 | 10 | /** 11 | * Representation of dedicated server 12 | */ 13 | class CDedicatedServer 14 | { 15 | public: 16 | CDedicatedServer(IExtendedSocket* socket, int ip, int port); 17 | 18 | void SetRoom(IRoom* room); 19 | void SetMemoryUsage(int memShift); 20 | 21 | IExtendedSocket* GetSocket(); 22 | IRoom* GetRoom(); 23 | int GetMemoryUsage(); 24 | int GetIP(); 25 | int GetPort(); 26 | 27 | private: 28 | IExtendedSocket* m_pSocket; 29 | IRoom* m_pRoom; 30 | 31 | int m_iLastMemory; 32 | int m_iIP; 33 | int m_iPort; 34 | }; 35 | 36 | /** 37 | * Dedicated server manager. 38 | * Processes messages from dedi servers, pool management 39 | */ 40 | class CDedicatedServerManager : public CBaseManager 41 | { 42 | public: 43 | CDedicatedServerManager(); 44 | ~CDedicatedServerManager(); 45 | 46 | virtual void Shutdown(); 47 | 48 | bool OnPacket(CReceivePacket* msg, IExtendedSocket* socket); 49 | 50 | void AddServer(IExtendedSocket* socket, int ip, int port); 51 | 52 | CDedicatedServer* GetAvailableServerFromPools(IRoom* room); 53 | bool IsPoolAvailable(); 54 | CDedicatedServer* GetServerBySocket(IExtendedSocket* socket); 55 | void RemoveServer(IExtendedSocket* socket); 56 | void TransferServer(IExtendedSocket* socket, const std::string& ipAddress, int port); 57 | std::vector& GetServers(); 58 | 59 | private: 60 | std::vector m_vServerPools; 61 | }; 62 | 63 | extern CDedicatedServerManager g_DedicatedServerManager; -------------------------------------------------------------------------------- /src/manager/hostmanager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "interface/ihostmanager.h" 4 | #include "manager.h" 5 | 6 | #include "user/user.h" 7 | 8 | class CHostManager : public CBaseManager 9 | { 10 | public: 11 | CHostManager(); 12 | ~CHostManager(); 13 | 14 | bool OnPacket(CReceivePacket* msg, IExtendedSocket* socket); 15 | 16 | void OnHostChanged(IUser* gameMatchUser, IUser* newHost, CGameMatch* match); 17 | private: 18 | bool OnSaveData(CReceivePacket* msg, CGameMatch* gameMatch); 19 | bool OnSetUserInventory(CReceivePacket* msg, IExtendedSocket* socket, IRoom* room, CGameMatch* gameMatch); 20 | bool OnUseInGameItem(CReceivePacket* msg, IExtendedSocket* socket, IRoom* room); 21 | bool OnFlyerFlockRequest(CReceivePacket* msg, IExtendedSocket* socket); 22 | bool OnUpdateUserStatus(CReceivePacket* msg, IExtendedSocket* socket, IRoom* room, CGameMatch* gameMatch); 23 | bool OnKillEvent(CReceivePacket* msg, IRoom* room, CGameMatch* gameMatch); 24 | bool OnUpdateKillCounter(CReceivePacket* msg, IRoom* room, CGameMatch* gameMatch); 25 | bool OnUpdateDeathCounter(CReceivePacket* msg, IRoom* room, CGameMatch* gameMatch); 26 | bool OnUpdateWinCounter(CReceivePacket* msg, CGameMatch* gameMatch); 27 | bool OnUpdateScore(CReceivePacket* msg, IRoom* room, CGameMatch* gameMatch); 28 | bool OnGameEvent(CReceivePacket* msg, IRoom* room, CGameMatch* gameMatch); 29 | bool OnUpdateClass(CReceivePacket* msg, IRoom* room, CGameMatch* gameMatch); 30 | bool OnZbsResult(CReceivePacket* msg, IExtendedSocket* socket); 31 | bool OnGameEnd(IExtendedSocket* socket); 32 | bool OnUserWeapon(CReceivePacket* msg, IExtendedSocket* socket); 33 | bool OnUserSpawn(CReceivePacket* msg, IExtendedSocket* socket); 34 | bool OnRoundStart(CReceivePacket* msg, IExtendedSocket* socket); 35 | bool OnChangeMap(CReceivePacket* msg, IRoom* room); 36 | }; 37 | 38 | extern CHostManager g_HostManager; -------------------------------------------------------------------------------- /src/manager/itemmanager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "interface/iitemmanager.h" 4 | #include "manager/usermanager.h" 5 | #include "definitions.h" 6 | #include "csvtable.h" 7 | 8 | #define ITEM_ADD_SUCCESS 1 9 | #define ITEM_ADD_INVENTORY_FULL -1 10 | #define ITEM_ADD_UNKNOWN_ITEMID -2 11 | #define ITEM_ADD_DB_ERROR -3 12 | 13 | #define ITEM_USE_SUCCESS 1 14 | #define ITEM_USE_BAD_SLOT -1 15 | #define ITEM_USE_WRONG_ITEM -2 16 | 17 | class CItemManager : public CBaseManager 18 | { 19 | public: 20 | CItemManager(); 21 | ~CItemManager(); 22 | 23 | virtual bool Init(); 24 | virtual void Shutdown(); 25 | 26 | bool LoadRewards(); 27 | bool LoadWeaponPaints(); 28 | bool KVToJson(); 29 | bool OnItemPacket(CReceivePacket* msg, IExtendedSocket* socket); 30 | int AddItem(int userID, IUser* user, int itemId, int count, int duration, int lockStatus = 0); 31 | int AddItems(int userID, IUser* user, std::vector& item); 32 | bool RemoveItem(int userID, IUser* user, CUserInventoryItem& item); 33 | int UseItem(IUser* user, int slot, int additionalArg = 0, int additionalArg2 = 0); 34 | bool CanUseItem(const CUserInventoryItem& item); 35 | bool OpenDecoder(IUser* user, int count, int slot); 36 | int ExtendItem(int userID, IUser* user, CUserInventoryItem& item, int newExpiryDate, bool duration = false); 37 | bool OnDisassembleRequest(IUser* user, CReceivePacket* msg); 38 | RewardNotice GiveReward(int userID, IUser* user, int rewardID, int rewardSelectID = 0, bool ignoreClient = false, int randomRepeatCount = 0); 39 | 40 | void OnUserLogin(IUser* user); 41 | void OnNicknameChangeUse(IUser* user, std::string newNickname); 42 | void OnRewardSelect(CReceivePacket* msg, IUser* user); 43 | void OnCostumeEquip(IUser* user, int slot); 44 | bool OnItemUse(IUser* user, CUserInventoryItem& item, int count = 1); 45 | 46 | Reward* GetRewardByID(int rewardID); 47 | std::vector GetWeaponPaints(); 48 | 49 | private: 50 | bool OnDailyRewardsRequest(IUser* user, int requestId); 51 | bool OnEnhancementRequest(IUser* user, CReceivePacket* msg); 52 | bool OnWeaponPaintRequest(IUser* user, CReceivePacket* msg); 53 | bool OnWeaponPaintSwitchRequest(IUser* user, CReceivePacket* msg); 54 | bool OnPartEquipRequest(IUser* user, CReceivePacket* msg); 55 | bool OnSwitchInUseRequest(IUser* user, CReceivePacket* msg); 56 | bool OnLockItemRequest(IUser* user, CReceivePacket* msg); 57 | 58 | // enhance funcs 59 | void InsertExp(IUser* user, CUserInventoryItem& targetItem, std::vector& items); 60 | 61 | std::vector m_Rewards; 62 | std::vector m_WeaponPaints; 63 | 64 | CCSVTable* m_pReinforceMaxLvTable; 65 | CCSVTable* m_pReinforceMaxExpTable; 66 | }; 67 | 68 | extern CItemManager g_ItemManager; -------------------------------------------------------------------------------- /src/manager/luckyitemmanager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "interface/iluckyitemmanager.h" 4 | #include "usermanager.h" 5 | #include "manager.h" 6 | 7 | class CLuckyItemManager : public CBaseManager 8 | { 9 | public: 10 | CLuckyItemManager(); 11 | ~CLuckyItemManager(); 12 | 13 | virtual bool Init(); 14 | virtual void Shutdown(); 15 | 16 | void LoadLuckyItems(); 17 | int OpenItemBox(IUser* user, int itemBox, int itemBoxOpenCount); 18 | std::vector& GetItemBoxes(); 19 | std::vector& GetItems(); 20 | ItemBox* GetItemBoxByItemId(int itemId); 21 | 22 | private: 23 | bool KVToJson(); // TODO: delete sometime 24 | 25 | std::vector m_Items; 26 | std::vector m_ItemBoxes; 27 | }; 28 | 29 | extern CLuckyItemManager g_LuckyItemManager; -------------------------------------------------------------------------------- /src/manager/manager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "interface/imanager.h" 7 | 8 | /** 9 | * Class for controlling all managers (init/shutdown all managers at the same time, calling tick method for all managers). 10 | * Only one instance allowed. 11 | */ 12 | class CManager : public IManager 13 | { 14 | private: 15 | CManager() = default; 16 | CManager(const CManager&) = delete; 17 | CManager(CManager&&) = delete; 18 | CManager& operator=(const CManager&) = delete; 19 | CManager& operator=(CManager&&) = delete; 20 | 21 | public: 22 | static CManager& GetInstance(); 23 | 24 | bool InitAll(); 25 | void ShutdownAll(); 26 | bool ReloadAll(); 27 | void AddManager(IBaseManager* pElem); 28 | void RemoveManager(IBaseManager* pElem); 29 | IBaseManager* GetManager(const std::string& name); 30 | void SecondTick(time_t curTime); 31 | void MinuteTick(time_t curTime); 32 | 33 | private: 34 | bool InitAll_Multithread(); 35 | 36 | std::vector m_Managers; 37 | }; 38 | 39 | extern CManager& Manager(); 40 | 41 | /** 42 | * Class that represents base manager. Every manager must inherit this class and every manager interface must inherit base manager interface. 43 | */ 44 | template 45 | class CBaseManager : public IInterface 46 | { 47 | public: 48 | CBaseManager(const std::string& name, bool secondTick = false, bool minuteTick = false) 49 | { 50 | m_Name = name; 51 | m_bSecondTick = secondTick; 52 | m_bMinuteTick = minuteTick; 53 | m_bCanReload = true; 54 | 55 | Manager().AddManager(this); 56 | } 57 | 58 | virtual ~CBaseManager() 59 | { 60 | printf("~CBaseManager called, %p\n\n", this); 61 | 62 | Manager().RemoveManager(this); 63 | } 64 | 65 | // stub methods 66 | virtual bool Init() { return true; } 67 | virtual void Shutdown() { printf("%s Shutdown called, %p\n", GetName().c_str(), this); } 68 | virtual bool CanReload() { return m_bCanReload; } 69 | virtual std::string GetName() { return m_Name; } 70 | virtual void OnSecondTick(time_t curTime) {} 71 | virtual void OnMinuteTick(time_t curTime) {} 72 | virtual bool ShouldDoSecondTick() { return m_bSecondTick; } 73 | virtual bool ShouldDoMinuteTick() { return m_bMinuteTick; } 74 | 75 | void SetMinuteTick(bool tick) { m_bMinuteTick = tick; } 76 | void SetSecondTick(bool tick) { m_bSecondTick = tick; } 77 | void SetCanReload(bool canReload) { m_bCanReload = canReload; } 78 | 79 | private: 80 | std::string m_Name; 81 | bool m_bSecondTick; 82 | bool m_bMinuteTick; 83 | bool m_bCanReload; 84 | }; 85 | -------------------------------------------------------------------------------- /src/manager/minigamemanager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "interface/iminigamemanager.h" 4 | 5 | #include "usermanager.h" 6 | 7 | class CMiniGameManager : public CBaseManager 8 | { 9 | public: 10 | CMiniGameManager(); 11 | ~CMiniGameManager(); 12 | 13 | void OnPacket(CReceivePacket* msg, IExtendedSocket* socket); 14 | 15 | void WeaponReleaseAddCharacter(IUser* user, char charID, int count); 16 | 17 | void SendWeaponReleaseUpdate(IUser* user); 18 | 19 | void OnBingoUpdateRequest(IUser* user); 20 | 21 | private: 22 | // bingo 23 | void OnBingoRequest(CReceivePacket* msg, IUser* user); 24 | void OnBingoResetRequest(IUser* user); 25 | void OnBingoShuffleRequest(IUser* user); 26 | 27 | bool BingoInitDesk(IUser* user, UserBingo& bingo); 28 | bool BingoOpenRandomNumber(IUser* user, UserBingo& bingo); 29 | 30 | // weapon release 31 | void OnWeaponReleaseRequest(CReceivePacket* msg, IUser* user); 32 | void OnWeaponReleaseSetCharacterRequest(CReceivePacket* msg, IUser* user); 33 | void OnWeaponReleaseGetJokerRequest(IUser* user); 34 | }; 35 | 36 | extern CMiniGameManager g_MiniGameManager; -------------------------------------------------------------------------------- /src/manager/questmanager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "interface/iquestmanager.h" 4 | #include "manager.h" 5 | 6 | #include "definitions.h" 7 | #include "quest/quest.h" 8 | #include "quest/questevent.h" 9 | 10 | #include "nlohmann/json.hpp" 11 | 12 | class CQuestManager : public CBaseManager 13 | { 14 | public: 15 | CQuestManager(); 16 | ~CQuestManager(); 17 | 18 | virtual bool Init(); 19 | virtual void Shutdown(); 20 | 21 | void LoadQuests(); 22 | void LoadEventQuests(); 23 | void LoadClanQuests(); 24 | 25 | void ParseQuests(nlohmann::ordered_json& jQuests); 26 | void ParseTasks(CQuestEvent* quest, nlohmann::ordered_json& jTasks); 27 | void ParseCondititons(CQuestEventTask* task, nlohmann::ordered_json& jConditions); 28 | 29 | std::vector& GetQuests(); 30 | void OnPacket(CReceivePacket* msg, IExtendedSocket* socket); 31 | void OnTitlePacket(CReceivePacket* msg, IExtendedSocket* socket); 32 | 33 | void OnMatchMinuteTick(CGameMatchUserStat* userStat, CGameMatch* gameMatch); 34 | 35 | // ingame events 36 | void OnKillEvent(CGameMatchUserStat* userStat, CGameMatch* gameMatch, GameMatch_KillEvent& killEvent); 37 | void OnBombExplode(CGameMatchUserStat* userStat, CGameMatch* gameMatch); 38 | void OnBombDefuse(CGameMatchUserStat* userStat, CGameMatch* gameMatch); 39 | void OnHostageEscape(CGameMatchUserStat* userStat, CGameMatch* gameMatch); 40 | void OnMonsterKill(CGameMatchUserStat* userStat, CGameMatch* gameMatch, int monsterType); 41 | void OnMosquitoKill(CGameMatchUserStat* userStat, CGameMatch* gameMatch); 42 | void OnKiteKill(CGameMatchUserStat* userStat, CGameMatch* gameMatch); 43 | 44 | void OnLevelUpEvent(IUser* user, int level, int newLevel); 45 | void OnMatchEndEvent(CGameMatchUserStat* userStat, CGameMatch* gameMatch, int userTeam); 46 | void OnGameMatchLeave(IUser* user, std::vector& questProgress, std::vector& questsEventsProgress); 47 | void OnUserLogin(IUser* user); 48 | 49 | void OnQuestTaskFinished(IUser* user, UserQuestTaskProgress& taskProgress, CQuestTask* task, CQuest* quest); 50 | void OnQuestEventTaskFinished(IUser* user, UserQuestTaskProgress& taskProgress, CQuestEventTask* task, CQuestEvent* quest); 51 | void OnQuestFinished(IUser* user, CQuest* quest, UserQuestProgress& questProgress); 52 | void OnReceiveReward(IUser* user, int rewardID, int questID); 53 | void OnSpecialMissionRequest(IUser* user, CReceivePacket* msg); 54 | void OnSetFavouriteRequest(IUser* user, CReceivePacket* msg); 55 | void OnTitleSetPrefixRequest(IUser* user, CReceivePacket* msg); 56 | void OnTitleListSetRequest(IUser* user, CReceivePacket* msg); 57 | void OnTitleListRemoveRequest(IUser* user, CReceivePacket* msg); 58 | 59 | CQuest* GetQuest(int questID); 60 | CQuestEvent* GetEventQuest(int questID); 61 | QuestReward_s GetQuestReward(CQuest* quest, int rewardID); 62 | UserQuestProgress GetUserQuestProgress(CQuest* quest, int userID); 63 | UserQuestTaskProgress GetUserQuestTaskProgress(CQuest* quest, int userID, int taskID); 64 | 65 | private: 66 | std::vector m_Quests; 67 | std::vector m_EventQuests; 68 | std::vector m_ClanQuests; 69 | }; 70 | 71 | extern CQuestManager g_QuestManager; -------------------------------------------------------------------------------- /src/manager/rankmanager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "interface/irankmanager.h" 4 | #include "manager.h" 5 | 6 | class CRankManager : public CBaseManager 7 | { 8 | public: 9 | CRankManager(); 10 | ~CRankManager(); 11 | 12 | bool OnRankPacket(CReceivePacket* msg, IExtendedSocket* socket); 13 | 14 | private: 15 | bool OnRankInfoRequest(CReceivePacket* msg, IUser* user); 16 | bool OnRankInRoomRequest(CReceivePacket* msg, IUser* user); 17 | bool OnRankSearchNicknameRequest(CReceivePacket* msg, IUser* user); 18 | bool OnRankLeagueRequest(CReceivePacket* msg, IUser* user); 19 | bool OnRankUserInfoRequest(CReceivePacket* msg, IUser* user); 20 | }; 21 | 22 | extern CRankManager g_RankManager; -------------------------------------------------------------------------------- /src/manager/shopmanager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "interface/ishopmanager.h" 4 | #include "manager.h" 5 | 6 | class CShopManager : public CBaseManager 7 | { 8 | public: 9 | CShopManager(); 10 | ~CShopManager(); 11 | 12 | virtual bool Init(); 13 | virtual void Shutdown(); 14 | 15 | bool LoadProducts(); 16 | 17 | void OnShopPacket(CReceivePacket* msg, IExtendedSocket* socket); 18 | void GetProductBySubId(int productId, Product& product, SubProduct& subProduct); 19 | bool BuyProduct(IUser* user, int productTypeId, int productId); 20 | 21 | const std::vector& GetProducts(); 22 | const std::vector>& GetRecommendedProducts(); 23 | const std::vector& GetPopularProducts(); 24 | 25 | private: 26 | bool KVToJson(); 27 | 28 | std::vector m_Products; 29 | std::vector> m_RecommendedProducts; 30 | std::vector m_PopularProducts; 31 | }; 32 | 33 | extern CShopManager g_ShopManager; -------------------------------------------------------------------------------- /src/manager/userdatabase_shared.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef DB_PROXY 4 | #define REAL_DATABASE_NAME "RealUserDatabase" 5 | #else 6 | #define REAL_DATABASE_NAME "UserDatabase" 7 | #endif 8 | -------------------------------------------------------------------------------- /src/manager/voxelmanager.cpp: -------------------------------------------------------------------------------- 1 | #include "voxelmanager.h" 2 | #include "packetmanager.h" 3 | #include "serverconfig.h" 4 | 5 | CVoxelManager g_VoxelManager; 6 | 7 | CVoxelManager::CVoxelManager() : CBaseManager("VoxelManager") 8 | { 9 | } 10 | 11 | CVoxelManager::~CVoxelManager() 12 | { 13 | } 14 | 15 | bool CVoxelManager::OnPacket(CReceivePacket* msg, IExtendedSocket* socket) 16 | { 17 | LOG_PACKET; 18 | 19 | int type = msg->ReadUInt8(); 20 | switch (type) 21 | { 22 | case 4: 23 | g_PacketManager.SendVoxelUnk4(socket); 24 | break; 25 | case 8: 26 | g_PacketManager.SendVoxelUnk8(socket); 27 | break; 28 | case 9: 29 | g_PacketManager.SendVoxelUnk9(socket); 30 | break; 31 | case 10: 32 | g_PacketManager.SendVoxelUnk10(socket); 33 | break; 34 | case 38: 35 | g_PacketManager.SendVoxelUnk38(socket); 36 | break; 37 | case 46: 38 | g_PacketManager.SendVoxelUnk46(socket); 39 | break; 40 | case 47: 41 | g_PacketManager.SendVoxelUnk47(socket); 42 | break; 43 | case 58: 44 | g_PacketManager.SendVoxelUnk58(socket); 45 | break; 46 | default: 47 | Logger().Warn("Unknown voxel request %d\n", type); 48 | break; 49 | } 50 | 51 | return true; 52 | } 53 | 54 | static const int TIMEOUT = 3000; 55 | 56 | std::string CVoxelManager::GetSlotDetails(const std::string& slotId) 57 | { 58 | sockaddr_in servaddr; 59 | memset(&servaddr, 0, sizeof(servaddr)); 60 | servaddr.sin_family = AF_INET; 61 | if (inet_pton(AF_INET, g_pServerConfig->voxelHTTPIP.c_str(), &servaddr.sin_addr) == 0) 62 | { 63 | Logger().Warn("CVoxelManager::GetSlotDetails: Error parsing host address.\n"); 64 | return ""; 65 | } 66 | servaddr.sin_port = htons(stoi(g_pServerConfig->voxelHTTPPort)); 67 | 68 | SOCKET sock = socket(AF_INET, SOCK_STREAM, IPPROTO_IP); 69 | 70 | setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, reinterpret_cast(&TIMEOUT), sizeof(TIMEOUT)); 71 | 72 | if (sock < 0) 73 | { 74 | Logger().Warn("CVoxelManager::GetSlotDetails: Error creating socket.\n"); 75 | return ""; 76 | } 77 | 78 | if (connect(sock, (struct sockaddr*)&servaddr, sizeof(servaddr)) < 0) 79 | { 80 | closesocket(sock); 81 | Logger().Warn("CVoxelManager::GetSlotDetails: Could not connect.\n"); 82 | return ""; 83 | } 84 | 85 | std::stringstream ss; 86 | ss << "GET /v6/slots/detail/" << slotId.c_str() << " HTTP/1.1\r\n" 87 | << "Connection: Keep-Alive\r\n" 88 | << "User-Agent: cpprestsdk/2.10.2\r\n" 89 | << "Host: " << g_pServerConfig->voxelHTTPIP << ":" << g_pServerConfig->voxelHTTPPort << "\r\n" 90 | << "\r\n\r\n"; 91 | std::string request = ss.str(); 92 | 93 | if (send(sock, request.c_str(), request.length(), 0) != (int)request.length()) 94 | { 95 | closesocket(sock); 96 | Logger().Warn("CVoxelManager::GetSlotDetails: Error sending request.\n"); 97 | return ""; 98 | } 99 | 100 | std::string response; 101 | char cur; 102 | bool found = false; 103 | while (recv(sock, &cur, 1, 0) > 0) 104 | { 105 | if (!found && cur == '{') 106 | found = true; 107 | 108 | if (found) 109 | response += cur; 110 | } 111 | 112 | closesocket(sock); 113 | return response; 114 | } -------------------------------------------------------------------------------- /src/manager/voxelmanager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "manager.h" 4 | #include "interface/ivoxelmanager.h" 5 | 6 | class IExtendedSocket; 7 | class CReceivePacket; 8 | class CRoomSettings; 9 | 10 | class CVoxelManager : public CBaseManager 11 | { 12 | public: 13 | CVoxelManager(); 14 | ~CVoxelManager(); 15 | 16 | bool OnPacket(CReceivePacket* msg, IExtendedSocket* socket); 17 | std::string GetSlotDetails(const std::string& slotId); 18 | }; 19 | 20 | extern CVoxelManager g_VoxelManager; -------------------------------------------------------------------------------- /src/net/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.20) 2 | 3 | project(net CXX) 4 | 5 | add_library(net STATIC) 6 | 7 | target_link_libraries(net PRIVATE wolfssl) 8 | 9 | target_sources(net PRIVATE "extendedsocket.cpp") 10 | target_sources(net PRIVATE "receivepacket.cpp") 11 | target_sources(net PRIVATE "sendpacket.cpp") 12 | target_sources(net PRIVATE "socketshared.cpp") 13 | target_sources(net PRIVATE "tcpclient.cpp") 14 | target_sources(net PRIVATE "tcpserver.cpp") 15 | target_sources(net PRIVATE "udpserver.cpp") 16 | 17 | target_sources(net PRIVATE "../common/utils.cpp") 18 | target_sources(net PRIVATE "../common/thread.cpp") 19 | target_sources(net PRIVATE "../common/buffer.cpp") 20 | target_sources(net PRIVATE "../common/logger.cpp") 21 | 22 | target_include_directories(net PUBLIC 23 | "../" 24 | "../public" 25 | "../thirdparty/wolfssl" 26 | "../thirdparty/json/include" 27 | ) -------------------------------------------------------------------------------- /src/net/net.h: -------------------------------------------------------------------------------- 1 | #ifdef WIN32 2 | #include 3 | #include 4 | 5 | #define poll WSAPoll 6 | #else 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #define WSAEWOULDBLOCK EWOULDBLOCK 15 | #define WSAECONNREFUSED ECONNREFUSED 16 | #define WSAECONNABORTED ECONNABORTED 17 | #define WSAECONNRESET ECONNRESET 18 | 19 | #define ioctlsocket ioctl 20 | #define closesocket close 21 | 22 | #define SOCKET_ERROR -1 23 | #define INVALID_SOCKET -1 24 | #endif -------------------------------------------------------------------------------- /src/net/socketshared.cpp: -------------------------------------------------------------------------------- 1 | #include "net/socketshared.h" 2 | 3 | /** 4 | * Listen thread for server/client 5 | * @param data Pointer to the listener object 6 | * @return NULL 7 | */ 8 | void* ListenThread(void* data) 9 | { 10 | ISocketListenable* listener = static_cast(data); 11 | 12 | while (listener->IsRunning()) 13 | { 14 | listener->Listen(); 15 | } 16 | 17 | return 0; 18 | } -------------------------------------------------------------------------------- /src/packet/packethelper_fulluserinfo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "net/receivepacket.h" 4 | #include "user/user.h" 5 | 6 | class CPacketHelper_FullUserInfo 7 | { 8 | public: 9 | CPacketHelper_FullUserInfo(); 10 | 11 | void Build(Buffer& buf, int userID, const CUserCharacter& character); 12 | }; 13 | -------------------------------------------------------------------------------- /src/packet/packetin_udp.cpp: -------------------------------------------------------------------------------- 1 | #include "packetin_udp.h" 2 | 3 | CPacketIn_UDP::CPacketIn_UDP(Buffer& buf) 4 | { 5 | buffer = buf; 6 | } 7 | 8 | void CPacketIn_UDP::Parse() 9 | { 10 | m_nSignature = buffer.readUInt8(); 11 | if (m_nSignature != 'W') 12 | { 13 | Logger().Error("CPacketIn_UDP::Parse: signature error\n"); 14 | } 15 | m_nUserID = buffer.readUInt32_LE(); 16 | m_nPortID = buffer.readUInt16_LE(); 17 | long longAddr = buffer.readUInt32_BE(); 18 | m_IpAddress = ip_to_string(longAddr); 19 | m_nPort = buffer.readUInt16_LE(); 20 | } -------------------------------------------------------------------------------- /src/packet/packetin_udp.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "receivepacket.h" 4 | 5 | class CPacketIn_UDP 6 | { 7 | public: 8 | CPacketIn_UDP(Buffer& buf); 9 | void Parse(); 10 | 11 | int m_nSignature; 12 | int m_nUserID; 13 | int m_nPortID; 14 | string m_IpAddress; 15 | int m_nPort; 16 | 17 | private: 18 | Buffer buffer; 19 | }; 20 | -------------------------------------------------------------------------------- /src/public/net/extendedsocket.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "interface/net/iextendedsocket.h" 4 | #include "common/buffer.h" 5 | 6 | struct GuestData_s 7 | { 8 | bool isGuest; 9 | 10 | class CChannelServer* currentServer; 11 | class CChannel* currentChannel; 12 | 13 | int launcherVersion; 14 | }; 15 | 16 | class CSendPacket; 17 | class CReceivePacket; 18 | struct WOLFSSL_EVP_CIPHER_CTX; 19 | 20 | /** 21 | * Class that extends client sockets and sockets returned by accept() to store additional information 22 | * such as IP, some statistics, etc and to manage packets 23 | */ 24 | class CExtendedSocket : public IExtendedSocket 25 | { 26 | public: 27 | CExtendedSocket(SOCKET socket, unsigned int id = 0); 28 | ~CExtendedSocket(); 29 | 30 | bool SetupCrypt(); 31 | void SetIP(const std::string& addr) { m_IP = addr; } 32 | void SetHWID(const std::vector& hwid) { m_HWID = hwid; } 33 | const std::string& GetIP() { return m_IP; } 34 | const std::vector& GetHWID() { return m_HWID; } 35 | void SetCryptInput(bool val) { m_bCryptInput = val; } 36 | void SetCryptOutput(bool val) { m_bCryptOutput = val; } 37 | unsigned char* GetCryptKey() { return m_pCryptKey; } 38 | unsigned char* GetCryptIV() { return m_pCryptIV; } 39 | WOLFSSL*& GetSSLObject() { return m_pSSL; } 40 | void SetSSLObject(WOLFSSL* ssl) { m_pSSL = ssl; } 41 | int GetSeq(); 42 | int LoggerGetSeq(); 43 | void ResetSeq(); 44 | int Read(char* buf, int len); 45 | CReceivePacket* Read(); 46 | int Send(std::vector& buffer, bool serverHelloMsg = false); 47 | int Send(CSendPacket* msg, bool ignoreQueue = false); 48 | 49 | // tcp client method 50 | bool OnServerConnected(); 51 | 52 | unsigned int GetID(); 53 | SOCKET GetSocket(); 54 | void SetMsg(CReceivePacket* msg); 55 | CReceivePacket* GetMsg(); 56 | int GetReadResult(); 57 | int GetBytesReceived(); 58 | int GetBytesSent(); 59 | std::vector& GetPacketsToSend(); 60 | GuestData_s& GetGuestData(); 61 | 62 | private: 63 | unsigned int m_nID; 64 | SOCKET m_Socket; 65 | int m_nSequence; 66 | int m_nBytesReceived; 67 | int m_nBytesSent; 68 | 69 | GuestData_s m_GuestData; 70 | 71 | CReceivePacket* m_pMsg; 72 | 73 | int m_nPacketReceivedSize; 74 | int m_nPacketSentSize; 75 | 76 | int m_nReadResult; 77 | int m_nNextExpectedSeq; // TODO: we need it? 78 | 79 | std::string m_IP; 80 | std::vector m_HWID; 81 | std::vector m_SendPackets; 82 | 83 | // crypt things 84 | WOLFSSL_EVP_CIPHER_CTX* m_pDecEVPCTX; 85 | WOLFSSL_EVP_CIPHER_CTX* m_pEncEVPCTX; 86 | bool m_bCryptInput; 87 | bool m_bCryptOutput; 88 | unsigned char m_pCryptKey[64]; 89 | unsigned char m_pCryptIV[64]; 90 | WOLFSSL* m_pSSL; 91 | }; 92 | -------------------------------------------------------------------------------- /src/public/net/receivepacket.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "common/buffer.h" 4 | 5 | /** 6 | * Class that represents incoming packets. 7 | */ 8 | class CReceivePacket 9 | { 10 | public: 11 | CReceivePacket(const Buffer& buf); 12 | 13 | bool IsValid(); 14 | int GetID(); 15 | int GetLength(); 16 | int GetSequence(); 17 | Buffer& GetData(); 18 | int8_t ReadInt8(); 19 | int16_t ReadInt16(bool bigEndian = false); 20 | int32_t ReadInt32(bool bigEndian = false); 21 | int64_t ReadInt64(bool bigEndian = false); 22 | uint8_t ReadUInt8(); 23 | uint16_t ReadUInt16(bool bigEndian = false); 24 | uint32_t ReadUInt32(bool bigEndian = false); 25 | uint64_t ReadUInt64(bool bigEndian = false); 26 | float ReadFloat(bool bigEndian = false); 27 | std::string ReadString(); 28 | std::vector ReadArray(int length); 29 | bool CanReadBytes(int len); 30 | void ParseHeader(); 31 | void SetBufferAndParse(const Buffer& buf); 32 | 33 | private: 34 | // packet header 35 | int m_nSignature; 36 | int m_nSequence; 37 | int m_nLength; 38 | int m_nPacketID; 39 | 40 | Buffer m_Buffer; 41 | }; 42 | -------------------------------------------------------------------------------- /src/public/net/sendpacket.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "common/buffer.h" 4 | 5 | /** 6 | * Class that represents outgoing packets. 7 | */ 8 | class CSendPacket 9 | { 10 | public: 11 | CSendPacket(int sequence, int packetID); 12 | ~CSendPacket(); 13 | 14 | std::vector SetPacketLength(); 15 | Buffer GetData(); 16 | void WriteInt8(int number); 17 | void WriteInt16(int number, bool littleEndian = true); 18 | void WriteInt32(int number, bool littleEndian = true); 19 | void WriteInt64(long long number, bool littleEndian = true); 20 | void WriteUInt8(unsigned int number); 21 | void WriteUInt16(unsigned int number, bool littleEndian = true); 22 | void WriteUInt32(unsigned int number, bool littleEndian = true); 23 | void WriteUInt64(unsigned long long number, bool littleEndian = true); 24 | void WriteString(const std::string& str); 25 | void WriteWString(const std::wstring& str); 26 | void WriteData(void* data, size_t len); 27 | void WriteArray(const std::vector& arr); 28 | void SetWriteOffset(int offset); 29 | void SetOverride(bool override); 30 | bool IsBufferFull(); 31 | void BuildHeader(); 32 | 33 | public: 34 | int m_nPacketID; 35 | int m_nSequence; 36 | 37 | Buffer m_OutStream; 38 | }; 39 | -------------------------------------------------------------------------------- /src/public/net/socketshared.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "net/net.h" 4 | 5 | void* ListenThread(void* data); 6 | 7 | class ISocketListenable 8 | { 9 | public: 10 | virtual void Listen() = 0; 11 | virtual bool IsRunning() = 0; 12 | }; -------------------------------------------------------------------------------- /src/public/net/tcpclient.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "socketshared.h" 4 | #include "common/thread.h" 5 | 6 | #include 7 | 8 | class CExtendedSocket; 9 | class IClientListenerTCP; 10 | 11 | /** 12 | * Class that connects to the server on a given IP and port 13 | */ 14 | class CTCPClient : public ISocketListenable 15 | { 16 | public: 17 | CTCPClient(); 18 | ~CTCPClient(); 19 | 20 | bool Start(const std::string& ip, const std::string& port); 21 | void Stop(); 22 | void Listen(); 23 | 24 | bool IsRunning(); 25 | 26 | void SetListener(IClientListenerTCP* listener); 27 | void SetCriticalSection(CCriticalSection* criticalSection); 28 | 29 | CExtendedSocket* GetSocket(); 30 | 31 | private: 32 | CExtendedSocket* m_pSocket; 33 | bool m_bIsRunning; 34 | bool m_nResult; 35 | CThread m_ListenThread; 36 | IClientListenerTCP* m_pListener; 37 | CCriticalSection* m_pCriticalSection; 38 | 39 | fd_set m_FdsRead; 40 | fd_set m_FdsWrite; 41 | fd_set m_FdsExcept; 42 | 43 | bool m_bConnected; // true when server connected msg received 44 | }; -------------------------------------------------------------------------------- /src/public/net/tcpserver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "socketshared.h" 4 | #include "common/thread.h" 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | class IExtendedSocket; 12 | class CExtendedSocket; 13 | class IServerListenerTCP; 14 | 15 | /** 16 | * Class that accepts TCP connection 17 | */ 18 | class CTCPServer : public ISocketListenable 19 | { 20 | public: 21 | CTCPServer(); 22 | ~CTCPServer(); 23 | 24 | bool Start(const std::string& port, int tcpSendBufferSize, bool ssl); 25 | void Stop(); 26 | void Listen(); 27 | void InitSSLContext(); 28 | 29 | IExtendedSocket* Accept(unsigned int id); 30 | IExtendedSocket* GetExSocketBySocket(SOCKET socket); 31 | void DisconnectClient(IExtendedSocket* socket); 32 | std::vector& GetClients(); 33 | 34 | bool IsRunning(); 35 | 36 | void SetListener(IServerListenerTCP* listener); 37 | void SetCriticalSection(CCriticalSection* criticalSection); 38 | 39 | private: 40 | SOCKET m_Socket; 41 | bool m_bIsRunning; 42 | int m_nResult; 43 | CThread m_ListenThread; 44 | unsigned int m_nNextClientIndex; 45 | std::vector m_Clients; 46 | IServerListenerTCP* m_pListener; 47 | CCriticalSection* m_pCriticalSection; 48 | 49 | std::vector m_fds; 50 | WOLFSSL_CTX* m_pCTX; 51 | }; -------------------------------------------------------------------------------- /src/public/net/udpserver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "socketshared.h" 4 | #include "common/thread.h" 5 | #include "common/buffer.h" 6 | 7 | #include 8 | 9 | class IServerListenerUDP; 10 | 11 | /** 12 | * Class that communicates with UDP clients 13 | */ 14 | class CUDPServer : public ISocketListenable 15 | { 16 | public: 17 | CUDPServer(); 18 | ~CUDPServer(); 19 | 20 | bool Start(const std::string& port); 21 | void Stop(); 22 | void Listen(); 23 | void SendTo(const Buffer& buf); 24 | 25 | bool IsRunning(); 26 | 27 | void SetListener(IServerListenerUDP* listener); 28 | void SetCriticalSection(CCriticalSection* criticalSection); 29 | 30 | private: 31 | SOCKET m_Socket; 32 | bool m_bIsRunning; 33 | int m_nResult; 34 | CThread m_ListenThread; 35 | IServerListenerUDP* m_pListener; 36 | CCriticalSection* m_pCriticalSection; 37 | char m_Buffer[5000]; 38 | 39 | fd_set m_FdsMaster; 40 | fd_set m_FdsRead; 41 | int m_nMaxFD; 42 | 43 | // last address got from recvfrom 44 | sockaddr_in m_LastAddr; 45 | int m_nLastAddrLen; 46 | }; -------------------------------------------------------------------------------- /src/room/gamematch.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "user/user.h" 4 | #include "user/userinventoryitem.h" 5 | 6 | #include "room/room.h" 7 | 8 | class CUserInventoryItem; 9 | 10 | class CGameMatchUserStat 11 | { 12 | public: 13 | CGameMatchUserStat(); 14 | 15 | void IncrementScore(int score); 16 | void UpdateKillsCount(int kills); 17 | void UpdateDeathsCount(int deaths); 18 | void UpdateClass(int classItemID); 19 | void UpdateItems(std::vector items); 20 | 21 | // zbs stuff 22 | void UpdateZbsRank(int rankPoints); 23 | 24 | void IncrementKillCount(); 25 | 26 | UserQuestProgress& GetTempQuestProgress(int questID); 27 | UserQuestTaskProgress& GetTempQuestTaskProgress(int questID, int taskID); 28 | 29 | UserQuestProgress& GetTempQuestEventProgress(int questID); 30 | UserQuestTaskProgress& GetTempQuestEventTaskProgress(int questID, int taskID); 31 | 32 | CUserInventoryItem* GetItem(int itemID); 33 | 34 | IUser* m_pUser; 35 | int m_nScore; 36 | int m_nKills; 37 | int m_nDeaths; 38 | int m_nPointsEarned; 39 | int m_nBonusPointsEarned; 40 | int m_nExpEarned; 41 | int m_nBonusExpEarned; 42 | int m_nItemBonusPoints; 43 | int m_nItemBonusExp; 44 | int m_nClassBonusPoints; 45 | int m_nClassBonusExp; 46 | int m_nClanBonusPoints; 47 | int m_nClanBonusExp; 48 | int m_nEventBonusPoints; 49 | int m_nEventBonusExp; 50 | int m_nPlayerCoopBonusPoints; 51 | int m_nPlayerCoopBonusExp; 52 | int m_nClassItemID; 53 | bool m_nIsLevelUp; 54 | std::vector m_TempQuestProgress; 55 | std::vector m_TempQuestEventProgress; 56 | std::vector m_Items; 57 | 58 | // zbs 59 | int m_nRank; 60 | }; 61 | 62 | class CGameMatch 63 | { 64 | public: 65 | CGameMatch(IRoom* room, int gameMode, int mapID); 66 | ~CGameMatch(); 67 | 68 | void Connect(IUser* user); 69 | void Disconnect(IUser* user); 70 | CGameMatchUserStat* GetGameUserStat(IUser* user); 71 | 72 | // ingame events 73 | void OnUpdateScore(IUser* user, int score); 74 | void OnUpdateKillCounter(IUser* user, int kills); 75 | void OnUpdateDeathCounter(IUser* user, int deaths); 76 | void OnUpdateWinCounter(int ctWinCount, int tWinCount); 77 | void OnUpdateClass(IUser* user, int classItemID); 78 | void OnGameMatchEnd(); 79 | void OnKillEvent(IUser* user, GameMatch_KillEvent& killEvent); 80 | void OnBombExplode(IUser* user); 81 | void OnBombDefuse(IUser* user); 82 | void OnHostageEscape(IUser* user); 83 | void OnMonsterKill(IUser* user, int monsterType); 84 | void OnDropBoxPickup(IUser* user, int rewardID); 85 | void OnMosquitoKill(IUser* user); 86 | void OnKiteKill(IUser* user); 87 | 88 | int GetExpCoefficient(); 89 | int GetPointsCoefficient(); 90 | bool IsZombieMode(); 91 | void SetSaveData(const std::vector& saveData); 92 | std::vector& GetSaveData(); 93 | void OnHostChanged(IUser* newHost); 94 | void CalculateFirstPlace(); 95 | void CalculateGameResult(); 96 | void ApplyGameResult(); 97 | void PrintGameResult(); 98 | 99 | void OnZBSWin(); 100 | 101 | std::vector m_UserStats; 102 | 103 | int m_nGameMode; 104 | int m_nMapID; 105 | int m_nCtWinCount; 106 | int m_nTerWinCount; 107 | int m_nFirstPlaceUserId; 108 | 109 | private: 110 | int m_nSecondCounter; 111 | 112 | std::vector m_SaveData; 113 | 114 | IRoom* m_pParentRoom; 115 | }; -------------------------------------------------------------------------------- /src/room/room.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "interface/iroom.h" 4 | #include "roomsettings.h" 5 | #include "net/receivepacket.h" 6 | #include "definitions.h" 7 | 8 | class CGameMatch; 9 | class CDedicatedServer; // TODO: fix includes 10 | 11 | class CRoomUser 12 | { 13 | public: 14 | CRoomUser(IUser* user, RoomTeamNum team, RoomReadyStatus ready) 15 | { 16 | m_bIsIngame = false; 17 | m_pUser = user; 18 | m_Team = team; 19 | m_Ready = ready; 20 | } 21 | 22 | IUser* m_pUser; 23 | RoomTeamNum m_Team; 24 | RoomReadyStatus m_Ready; 25 | bool m_bIsIngame; 26 | }; 27 | 28 | class CRoom : public IRoom 29 | { 30 | public: 31 | CRoom(int roomId, IUser* hostUser, class CChannel* channel, CRoomSettings* settings); 32 | ~CRoom(); 33 | 34 | virtual void Shutdown(); 35 | 36 | int GetNumOfPlayers(); 37 | int GetFreeSlots(); 38 | bool HasFreeSlots(); 39 | bool HasPassword(); 40 | bool HasUser(IUser* user); 41 | void AddUser(IUser* user); 42 | enum RoomTeamNum FindDesirableTeamNum(); 43 | enum RoomTeamNum GetUserTeam(IUser* user); 44 | int GetNumOfReadyRealPlayers(); 45 | int GetNumOfRealCts(); 46 | int GetNumOfRealTerrorists(); 47 | int GetNumOfReadyPlayers(); 48 | RoomReadyStatus IsUserReady(IUser* user); 49 | bool IsRoomReady(); 50 | void SetUserIngame(IUser* user, bool inGame); 51 | void RemoveUser(IUser* targetUser); 52 | //void RemoveUserById(int userId); 53 | void SetUserToTeam(IUser* user, RoomTeamNum newTeam); 54 | enum RoomStatus GetStatus(); 55 | void SetStatus(RoomStatus newStatus); 56 | enum RoomReadyStatus ToggleUserReadyStatus(IUser* user); 57 | void ResetStatusIngameUsers(); 58 | //bool CanStartGame(); 59 | void OnUserRemoved(IUser* user); 60 | void SendRemovedUser(IUser* deletedUser); 61 | void UpdateHost(IUser* newHost); 62 | void HostStartGame(); 63 | void UserGameJoin(IUser* user); 64 | void EndGame(bool forcedEnd); 65 | bool FindAndUpdateNewHost(); 66 | void UpdateSettings(CRoomSettings& newSettings); 67 | void OnUserMessage(CReceivePacket* msg, IUser* user); 68 | void OnUserTeamMessage(CReceivePacket* msg, IUser* user); 69 | void OnGameStart(); 70 | void AddKickedUser(IUser* user); 71 | void ClearKickedUsers(); 72 | void KickUser(IUser* user); 73 | void VoteKick(IUser* user, bool kick); 74 | void SendJoinNewRoom(IUser* user); 75 | void SendRoomSettings(IUser* user); 76 | void SendUpdateRoomSettings(IUser* user, CRoomSettings* settings, int lowFlag, int lowMidFlag, int highMidFlag, int highFlag); 77 | void SendRoomUsersReadyStatus(IUser* user); 78 | void SendReadyStatusToAll(); 79 | void SendReadyStatusToAll(IUser* user); 80 | void SendNewUser(IUser* user, IUser* newUser); 81 | void SendUserReadyStatus(IUser* user, IUser* player); 82 | void SendConnectHost(IUser* user, IUser* host); 83 | void SendStartMatch(IUser* host); 84 | void SendCloseResultWindow(IUser* user); 85 | void SendTeamChange(IUser* user, IUser* player, RoomTeamNum newTeamNum); 86 | void SendGameEnd(IUser* user); 87 | void SendRoomStatus(IUser* user); 88 | void SendPlayerLeaveIngame(IUser* user); 89 | 90 | void CheckForHostItems(); 91 | 92 | int GetID(); 93 | IUser* GetHostUser(); 94 | std::vector GetUsers(); 95 | CRoomSettings* GetSettings(); 96 | CGameMatch* GetGameMatch(); 97 | CChannel* GetParentChannel(); 98 | bool IsUserKicked(int userID); 99 | 100 | CDedicatedServer* GetServer(); 101 | void SetServer(CDedicatedServer* server); 102 | void ChangeMap(int mapId); 103 | 104 | bool IsUserInFamilyBattleUsers(int userId); 105 | 106 | private: 107 | IUser* m_pHostUser; 108 | class CChannel* m_pParentChannel; 109 | CRoomSettings* m_pSettings; 110 | std::vector m_Users; 111 | CGameMatch* m_pGameMatch; 112 | std::vector m_KickedUsers; 113 | std::vector m_FamilyBattleUsers; 114 | 115 | CDedicatedServer* m_pServer; 116 | 117 | int m_nID; 118 | RoomStatus m_Status; 119 | }; -------------------------------------------------------------------------------- /src/serverconfig.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JusicP/CSNZ_Server/4859a6e73451ccbfce167b1d28deeb0457468ac3/src/serverconfig.cpp -------------------------------------------------------------------------------- /src/serverconfig.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "definitions.h" 4 | #include "nlohmann/json.hpp" 5 | 6 | using json = nlohmann::json; 7 | using ordered_json = nlohmann::ordered_json; 8 | 9 | class CServerConfig 10 | { 11 | public: 12 | CServerConfig(); 13 | ~CServerConfig(); 14 | 15 | bool Load(); 16 | void LoadDefaultConfig(ordered_json& cfg); 17 | 18 | std::string hostName; 19 | std::string description; 20 | std::string tcpPort; 21 | std::string udpPort; 22 | int tcpSendBufferSize; 23 | int maxPlayers; 24 | std::string welcomeMessage; 25 | bool restartOnCrash; 26 | int inventorySlotMax; 27 | bool checkClientBuild; 28 | int allowedClientTimestamp; 29 | int allowedLauncherVersion; 30 | int maxRegistrationsPerIP; 31 | uint64_t metadataToSend; 32 | DefaultUser defUser; 33 | std::vector notices; 34 | ServerConfigGameMatch_s gameMatch; 35 | ServerConfigRoom_s room; 36 | int activeMiniGamesFlag; 37 | int flockingFlyerType; 38 | ServerConfigBingo bingo; 39 | WeaponReleaseConfig weaponRelease; 40 | std::vector nameBlacklist; 41 | std::vector surveys; 42 | bool ssl; 43 | bool crypt; 44 | int mainMenuSkinEvent; 45 | int banListMaxSize; 46 | std::string voxelHTTPIP; 47 | std::string voxelHTTPPort; 48 | std::string voxelVxlURL; 49 | std::string voxelVmgURL; 50 | std::vector dedicatedServerWhitelist; 51 | }; 52 | 53 | extern class CServerConfig* g_pServerConfig; -------------------------------------------------------------------------------- /src/serverinstance.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "interface/iserverinstance.h" 4 | #include "interface/net/iserverlistener.h" 5 | #include "csvtable.h" 6 | 7 | #include "net/tcpserver.h" 8 | #include "net/udpserver.h" 9 | 10 | class CServerInstance : public IServerInstance, IServerListenerTCP, IServerListenerUDP 11 | { 12 | public: 13 | CServerInstance(); 14 | ~CServerInstance(); 15 | 16 | bool Init(); 17 | bool Reload(); 18 | bool LoadConfigs(); 19 | void UnloadConfigs(); 20 | 21 | virtual bool OnTCPConnectionCreated(IExtendedSocket* socket); 22 | virtual void OnTCPConnectionClosed(IExtendedSocket* socket); 23 | virtual void OnTCPMessage(IExtendedSocket* socket, CReceivePacket* msg); 24 | virtual void OnTCPError(int errorCode); 25 | 26 | virtual void OnUDPMessage(Buffer& buf, unsigned short port); 27 | virtual void OnUDPError(int errorCode); 28 | 29 | void SetServerActive(bool active); 30 | bool IsServerActive(); 31 | void OnCommand(const std::string& command); 32 | void OnEvent(); 33 | void OnPackets(IExtendedSocket* s, CReceivePacket* msg); 34 | void OnSecondTick(); 35 | void OnMinuteTick(); 36 | void OnFunction(std::function& func); 37 | virtual time_t GetCurrentTime(); 38 | virtual tm* GetCurrentLocalTime(); 39 | virtual double GetMemoryInfo(); 40 | virtual const char* GetMainInfo(); 41 | virtual void DisconnectClient(IExtendedSocket* socket); 42 | virtual std::vector GetClients(); 43 | virtual IExtendedSocket* GetSocketByID(unsigned int id); 44 | 45 | private: 46 | bool m_bIsServerActive; 47 | 48 | time_t m_CurrentTime; 49 | tm* m_pCurrentLocalTime; 50 | time_t m_nUptime; 51 | 52 | CTCPServer m_TCPServer; 53 | CUDPServer m_UDPServer; 54 | }; 55 | 56 | extern CServerInstance* g_pServerInstance; 57 | 58 | extern CCSVTable* g_pItemTable; 59 | extern CCSVTable* g_pMapListTable; 60 | extern CCSVTable* g_pGameModeListTable; 61 | 62 | void* ReadConsoleThread(void*); 63 | void* EventThread(void*); 64 | -------------------------------------------------------------------------------- /src/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(test) 2 | 3 | add_executable(test) 4 | 5 | include_directories(PRIVATE 6 | "../" 7 | "../public" 8 | "../common" 9 | "../thirdparty" 10 | "../thirdparty/doctest" 11 | "../thirdparty/json/include" 12 | ) 13 | 14 | add_subdirectory(net) 15 | 16 | target_sources(test PRIVATE "testserver.cpp") 17 | target_sources(test PRIVATE "testmanager.cpp") 18 | target_sources(test PRIVATE "../manager/manager.cpp") 19 | 20 | target_sources(test PRIVATE "testlogger.cpp") 21 | target_sources(test PRIVATE "../common/logger.cpp") 22 | 23 | target_sources(test PRIVATE "testevent.cpp") 24 | 25 | target_sources(test PRIVATE "testcommand.cpp") 26 | target_sources(test PRIVATE "../command.cpp") 27 | 28 | #target_sources(test PRIVATE "testlogger.cpp") 29 | #target_sources(test PRIVATE "../common/logger.cpp") 30 | 31 | target_sources(test PRIVATE "testevent.cpp") 32 | 33 | #target_sources(test PRIVATE "testquestmanager.cpp") 34 | #target_sources(test PRIVATE "../manager/questmanager.cpp") 35 | 36 | -------------------------------------------------------------------------------- /src/test/net/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(test_net) 2 | 3 | add_executable(test_net) 4 | 5 | target_sources(test_net PRIVATE "net.cpp") 6 | 7 | target_link_libraries(test_net PRIVATE net) 8 | -------------------------------------------------------------------------------- /src/test/net/net.cpp: -------------------------------------------------------------------------------- 1 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 2 | #include 3 | 4 | #include "testbasicfuncs.h" 5 | #include "testpacketsequence.h" 6 | 7 | #define TEST_PORT "30002" 8 | 9 | using namespace std; 10 | 11 | TEST_CASE("Network (TCP) - Test send/receive") 12 | { 13 | CTCPServer_TestBasicFuncs server(TEST_PORT); 14 | CTCPClient_TestBasicFuncs client("127.0.0.1", TEST_PORT); 15 | 16 | while (!server.m_bFailed && !server.m_bFinished) 17 | { 18 | // wait for the test finish/error 19 | } 20 | } 21 | 22 | TEST_CASE("Network (TCP) - Test packet sequence and/or segmentation") 23 | { 24 | CTCPServer_TestPacketSequence server(TEST_PORT); 25 | CTCPClient_TestPacketSequence client("127.0.0.1", TEST_PORT); 26 | 27 | while (!server.m_bFailed && !server.m_bFinished) 28 | { 29 | // wait for the test finish/error 30 | } 31 | } -------------------------------------------------------------------------------- /src/test/net/testbasicfuncs.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "net/tcpserver.h" 4 | #include "net/tcpclient.h" 5 | #include "net/sendpacket.h" 6 | #include "net/receivepacket.h" 7 | #include "net/extendedsocket.h" 8 | 9 | #include "interface/net/iserverlistener.h" 10 | 11 | using namespace std; 12 | 13 | /* 14 | * Server class to test network send/receive functionality 15 | */ 16 | class CTCPServer_TestBasicFuncs : public IServerListenerTCP 17 | { 18 | public: 19 | CTCPServer_TestBasicFuncs(const string& port) 20 | { 21 | m_bFinished = false; 22 | m_bFailed = false; 23 | 24 | m_Server.SetListener(this); 25 | REQUIRE(m_Server.Start(port, 128) == true); 26 | } 27 | 28 | bool OnTCPConnectionCreated(IExtendedSocket* socket) 29 | { 30 | // Send(Server -> Client) 31 | { 32 | // send message with id 1 33 | CSendPacket* msg = new CSendPacket(socket->GetSeq(), 1); 34 | msg->BuildHeader(); 35 | msg->WriteString("Hello from server"); 36 | 37 | size_t bufSize = msg->GetData().getBuffer().size(); 38 | int sentBytes = socket->Send(msg); 39 | if (socket->GetPacketsToSend().empty()) 40 | REQUIRE(sentBytes == bufSize); 41 | } 42 | 43 | return true; 44 | } 45 | 46 | void OnTCPConnectionClosed(IExtendedSocket* socket) 47 | { 48 | REQUIRE(m_bFinished == true); 49 | if (!m_bFinished) 50 | { 51 | m_bFailed = true; 52 | } 53 | } 54 | 55 | void OnTCPMessage(IExtendedSocket* socket, CReceivePacket* msg) 56 | { 57 | // Receive(Client -> Server) 58 | { 59 | CHECK(msg->GetSequence() == 1); 60 | CHECK(msg->GetID() == 2); 61 | CHECK(msg->ReadString() == "Hello from client"); 62 | } 63 | 64 | m_bFinished = true; 65 | delete msg; 66 | } 67 | 68 | void OnTCPError(int errorCode) 69 | { 70 | FAIL("Server error occurred"); 71 | m_bFailed = true; 72 | } 73 | 74 | CTCPServer m_Server; 75 | bool m_bFailed; 76 | bool m_bFinished; 77 | }; 78 | 79 | /* 80 | * Client class to test network send/receive functionality 81 | */ 82 | class CTCPClient_TestBasicFuncs : public IClientListenerTCP 83 | { 84 | public: 85 | CTCPClient_TestBasicFuncs(const string& ip, const string& port) 86 | { 87 | m_bConnected = false; 88 | 89 | m_Client.SetListener(this); 90 | REQUIRE(m_Client.Start(ip, port) == true); 91 | } 92 | 93 | void OnTCPServerConnected() 94 | { 95 | // server hello received 96 | m_bConnected = true; 97 | } 98 | 99 | void OnTCPServerConnectFailed() 100 | { 101 | FAIL("Server connect failed"); 102 | } 103 | 104 | void OnTCPMessage(CReceivePacket* msg) 105 | { 106 | REQUIRE(m_bConnected == true); 107 | 108 | // Receive(Server -> Client) 109 | { 110 | CHECK(msg->GetSequence() == 1); 111 | CHECK(msg->GetID() == 1); 112 | CHECK(msg->ReadString() == "Hello from server"); 113 | } 114 | 115 | // Send(Client -> Server) 116 | { 117 | // send message with id 2 118 | CSendPacket* sendMsg = new CSendPacket(m_Client.GetSocket()->GetSeq(), 2); 119 | sendMsg->BuildHeader(); 120 | sendMsg->WriteString("Hello from client"); 121 | 122 | size_t bufSize = sendMsg->GetData().getBuffer().size(); 123 | int sentBytes = m_Client.GetSocket()->Send(sendMsg); 124 | if (m_Client.GetSocket()->GetPacketsToSend().empty()) 125 | REQUIRE(sentBytes == bufSize); 126 | } 127 | 128 | delete msg; 129 | } 130 | 131 | void OnTCPError(int errorCode) 132 | { 133 | FAIL("Client error occurred"); 134 | } 135 | 136 | CTCPClient m_Client; 137 | bool m_bConnected; 138 | }; 139 | -------------------------------------------------------------------------------- /src/test/net/testpacketsequence.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "net/tcpserver.h" 4 | #include "net/tcpclient.h" 5 | #include "net/sendpacket.h" 6 | #include "net/receivepacket.h" 7 | #include "net/extendedsocket.h" 8 | #include "common/net/netdefs.h" 9 | 10 | #include "interface/net/iserverlistener.h" 11 | 12 | using namespace std; 13 | 14 | /* 15 | * Server class to test packet sequence reset 16 | */ 17 | class CTCPServer_TestPacketSequence : public IServerListenerTCP 18 | { 19 | public: 20 | CTCPServer_TestPacketSequence(const string& port) 21 | { 22 | m_bFinished = false; 23 | m_bFailed = false; 24 | 25 | m_Server.SetListener(this); 26 | REQUIRE(m_Server.Start(port, 128, false) == true); 27 | } 28 | 29 | bool OnTCPConnectionCreated(IExtendedSocket* socket) 30 | { 31 | // send 255 + 1 messages 32 | for (int i = 0; i < MAX_SEQUENCE + 1; i++) 33 | { 34 | CSendPacket* msg = new CSendPacket(socket->GetSeq(), 1); 35 | msg->BuildHeader(); 36 | msg->WriteUInt8(i); 37 | 38 | size_t bufSize = msg->GetData().getBuffer().size(); 39 | int sentBytes = socket->Send(msg); 40 | if (socket->GetPacketsToSend().empty()) 41 | REQUIRE(sentBytes == bufSize); 42 | } 43 | 44 | return true; 45 | } 46 | 47 | void OnTCPConnectionClosed(IExtendedSocket* socket) 48 | { 49 | REQUIRE(m_bFinished == true); 50 | if (!m_bFinished) 51 | { 52 | m_bFailed = true; 53 | } 54 | } 55 | 56 | void OnTCPMessage(IExtendedSocket* socket, CReceivePacket* msg) 57 | { 58 | // Receive(Client -> Server) 59 | // finish test after receiving 60 | if (msg->ReadUInt8() == MAX_SEQUENCE) 61 | m_bFinished = true; 62 | 63 | delete msg; 64 | } 65 | 66 | void OnTCPError(int errorCode) 67 | { 68 | FAIL("Server error occurred"); 69 | m_bFailed = true; 70 | } 71 | 72 | CTCPServer m_Server; 73 | bool m_bFailed; 74 | bool m_bFinished; 75 | }; 76 | 77 | /* 78 | * Client class to test packet sequence reset 79 | */ 80 | class CTCPClient_TestPacketSequence : public IClientListenerTCP 81 | { 82 | public: 83 | CTCPClient_TestPacketSequence(const string& ip, const string& port) 84 | { 85 | m_bConnected = false; 86 | 87 | m_Client.SetListener(this); 88 | REQUIRE(m_Client.Start(ip, port) == true); 89 | } 90 | 91 | void OnTCPServerConnected() 92 | { 93 | // server hello received 94 | m_bConnected = true; 95 | } 96 | 97 | void OnTCPServerConnectFailed() 98 | { 99 | FAIL("Server connect failed"); 100 | } 101 | 102 | void OnTCPMessage(CReceivePacket* msg) 103 | { 104 | REQUIRE(m_bConnected == true); 105 | 106 | // Receive(Server -> Client) 107 | CSendPacket* sendMsg = new CSendPacket(m_Client.GetSocket()->GetSeq(), msg->GetID()); 108 | sendMsg->BuildHeader(); 109 | sendMsg->WriteUInt8(msg->ReadUInt8()); 110 | 111 | size_t bufSize = sendMsg->GetData().getBuffer().size(); 112 | int sentBytes = m_Client.GetSocket()->Send(sendMsg); 113 | if (m_Client.GetSocket()->GetPacketsToSend().empty()) 114 | REQUIRE(sentBytes == bufSize); 115 | 116 | delete msg; 117 | } 118 | 119 | void OnTCPError(int errorCode) 120 | { 121 | FAIL("Client error occurred"); 122 | } 123 | 124 | CTCPClient m_Client; 125 | bool m_bConnected; 126 | }; 127 | -------------------------------------------------------------------------------- /src/test/testcommand.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "../command.h" 3 | 4 | using namespace std; 5 | 6 | TEST_CASE("Command - add, search, execute") 7 | { 8 | bool executed = false; 9 | auto commandFunc = [&executed](CCommand* cmd, const vector& args) { 10 | executed = true; 11 | }; 12 | 13 | const string cmdName = "test_cmd"; 14 | CCommand cmd(cmdName, "description", "", commandFunc); 15 | 16 | // check if can find command 17 | CHECK(CCommandList::GetInstance().GetCommand(cmdName)); 18 | 19 | // check if command in command list 20 | auto cmdList = CCommandList::GetInstance().GetCommandList(); 21 | CHECK(find(cmdList.begin(), cmdList.end(), cmdName) != cmdList.end()); 22 | 23 | cmd.Exec({}); 24 | 25 | // check if command executed 26 | CHECK(executed); 27 | } 28 | -------------------------------------------------------------------------------- /src/test/testevent.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "../event.h" 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | TEST_CASE("Events - test events") 9 | { 10 | // Add two events, call WaitForSignal() from another thread, check if events executed 11 | int counter = 0; 12 | auto func = [&counter]() { 13 | counter++; 14 | }; 15 | 16 | CEvents events; 17 | events.AddEventFunction(func); 18 | events.AddEventFunction(func); 19 | 20 | std::atomic done{ false }; 21 | 22 | auto eventThreadFunc = [&done, &events]() { 23 | events.WaitForSignal(); 24 | 25 | IEvent* ev = events.GetNextEvent(); 26 | 27 | CHECK(ev); 28 | ev->Execute(); 29 | ev = events.GetNextEvent(); 30 | 31 | CHECK(ev); 32 | ev->Execute(); 33 | ev = events.GetNextEvent(); 34 | 35 | CHECK(!ev); 36 | 37 | done = true; 38 | }; 39 | 40 | thread t(eventThreadFunc); 41 | 42 | // wait for a thread to end 43 | this_thread::sleep_for(200ms); 44 | 45 | // check if thread is done 46 | CHECK(done == true); 47 | 48 | t.join(); 49 | 50 | CHECK(counter == 2); 51 | } 52 | -------------------------------------------------------------------------------- /src/test/testlogger.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "../common/logger.h" 3 | 4 | using namespace std; 5 | 6 | #define TEST_MESSAGE_ARGS "%s %s %d\n", "test1", "test2", 227 7 | #define TEST_MESSAGE "test1 test2 227\n" 8 | 9 | #define BUF_SIZE 128 10 | 11 | TEST_CASE("Logger - test logger") 12 | { 13 | class CTestLogger : public CBaseLogger 14 | { 15 | public: 16 | CTestLogger() : CBaseLogger(false) 17 | { 18 | } 19 | 20 | void LogVarg(int level, const char* msg, va_list argptr) 21 | { 22 | CHECK(level == LogLevel::LOG_LEVEL_INFO); 23 | 24 | char buf[BUF_SIZE]; 25 | vsnprintf(buf, sizeof(buf), msg, argptr); 26 | 27 | CHECK(strcmp(buf, TEST_MESSAGE) == 0); 28 | } 29 | }; 30 | 31 | CTestLogger logger; 32 | logger.Info(TEST_MESSAGE_ARGS); 33 | } 34 | 35 | TEST_CASE("Logger - test logger with prefix") 36 | { 37 | class CTestLoggerPrefix : public CBaseLogger 38 | { 39 | public: 40 | CTestLoggerPrefix() : CBaseLogger(false) 41 | { 42 | } 43 | 44 | void LogVarg(int level, const char* msg, va_list argptr) 45 | { 46 | CHECK(level == LogLevel::LOG_LEVEL_INFO); 47 | 48 | char buf[BUF_SIZE]; 49 | vsnprintf(buf, sizeof(buf), msg, argptr); 50 | 51 | // check if string contains required message, the first part should be prefix 52 | CHECK(strstr(buf, TEST_MESSAGE) != 0); 53 | } 54 | }; 55 | 56 | CLoggerPrefix logger(new CTestLoggerPrefix()); 57 | logger.Info(TEST_MESSAGE_ARGS); 58 | } 59 | 60 | TEST_CASE("Logger - test composite logger") 61 | { 62 | class CTestLoggerComposite : public CBaseLogger 63 | { 64 | public: 65 | CTestLoggerComposite() : CBaseLogger(false) 66 | { 67 | } 68 | 69 | void LogVarg(int level, const char* msg, va_list argptr) 70 | { 71 | CHECK(level == LogLevel::LOG_LEVEL_INFO); 72 | 73 | // message must be already formatted 74 | CHECK(strcmp(msg, TEST_MESSAGE) == 0); 75 | CHECK(argptr == NULL); 76 | } 77 | }; 78 | 79 | CCompositeLogger logger(false, { new CTestLoggerComposite() }); 80 | logger.Info(TEST_MESSAGE_ARGS); 81 | } 82 | -------------------------------------------------------------------------------- /src/test/testmanager.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "../manager/manager.h" 3 | 4 | using namespace std; 5 | 6 | class ITestManager : public IBaseManager 7 | { 8 | public: 9 | virtual void DoSomething() = 0; 10 | }; 11 | 12 | /** 13 | * Test manager class to test basic functionality (init, shutdown, ticks) 14 | */ 15 | class CTestManager : public CBaseManager 16 | { 17 | public: 18 | CTestManager() : CBaseManager("TestManager", true, true) 19 | { 20 | m_bInitCalled = false; 21 | m_bShutdownCalled = false; 22 | m_bReloaded = false; 23 | m_bSecondTickCalled = false; 24 | m_bMinuteTickCalled = false; 25 | } 26 | 27 | virtual bool Init() 28 | { 29 | // ReloadAll called 30 | if (m_bInitCalled && m_bShutdownCalled) 31 | m_bReloaded = true; 32 | 33 | m_bInitCalled = true; 34 | return true; 35 | } 36 | 37 | virtual void Shutdown() 38 | { 39 | m_bShutdownCalled = true; 40 | } 41 | 42 | virtual void OnSecondTick(time_t curTime) 43 | { 44 | m_bSecondTickCalled = true; 45 | } 46 | 47 | virtual void OnMinuteTick(time_t curTime) 48 | { 49 | m_bMinuteTickCalled = true; 50 | } 51 | 52 | virtual void DoSomething() 53 | { 54 | } 55 | 56 | bool m_bInitCalled; 57 | bool m_bShutdownCalled; 58 | bool m_bReloaded; 59 | bool m_bSecondTickCalled; 60 | bool m_bMinuteTickCalled; 61 | }; 62 | 63 | TEST_CASE("Manager - Test init/shutdown, reload, remove, ticks") 64 | { 65 | CTestManager mgr; 66 | 67 | CHECK(Manager().GetManager("TestManager") != NULL); 68 | 69 | CHECK(Manager().InitAll() == true); 70 | CHECK(mgr.m_bInitCalled == true); 71 | 72 | SUBCASE("Test remove manager") 73 | { 74 | // test tick calling 75 | Manager().SecondTick(0); 76 | Manager().MinuteTick(0); 77 | 78 | CHECK(mgr.m_bSecondTickCalled == true); 79 | CHECK(mgr.m_bMinuteTickCalled == true); 80 | 81 | // test tick not calling 82 | mgr.m_bSecondTickCalled = false; 83 | mgr.m_bMinuteTickCalled = false; 84 | 85 | mgr.SetSecondTick(false); 86 | mgr.SetMinuteTick(false); 87 | 88 | Manager().SecondTick(0); 89 | Manager().MinuteTick(0); 90 | 91 | CHECK(mgr.m_bSecondTickCalled == false); 92 | CHECK(mgr.m_bMinuteTickCalled == false); 93 | } 94 | 95 | SUBCASE("Test remove manager") 96 | { 97 | Manager().RemoveManager(&mgr); 98 | CHECK(Manager().GetManager("TestManager") == NULL); 99 | } 100 | 101 | SUBCASE("Test shutdown all") 102 | { 103 | Manager().ShutdownAll(); 104 | CHECK(mgr.m_bShutdownCalled == true); 105 | } 106 | 107 | SUBCASE("Test reload all") 108 | { 109 | CHECK(Manager().ReloadAll() == true); 110 | CHECK(mgr.m_bReloaded == true); 111 | } 112 | 113 | SUBCASE("Test reload all if manager can't be reloaded") 114 | { 115 | mgr.SetCanReload(false); 116 | CHECK(Manager().ReloadAll() == true); 117 | CHECK(mgr.m_bReloaded == false); 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /src/test/testserver.cpp: -------------------------------------------------------------------------------- 1 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 2 | #include 3 | 4 | -------------------------------------------------------------------------------- /src/thirdparty/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(BUILD_SHARED_LIBS OFF) 2 | 3 | add_subdirectory(KeyValues) 4 | add_subdirectory(json) 5 | 6 | set(WOLFSSL_OPENSSLEXTRA "yes") 7 | set(WOLFSSL_EXAMPLES "no") 8 | set(WOLFSSL_ARC4 "yes") 9 | add_subdirectory(wolfssl) 10 | target_compile_definitions(wolfssl PRIVATE WOLFSSL_ALLOW_RC4=1) 11 | 12 | if (SERVER_DBSQLITE) 13 | set(SQLITECPP_USE_STATIC_RUNTIME OFF CACHE BOOL "Use MSVC static runtime (default for internal googletest).") 14 | add_subdirectory(SQLiteCpp) 15 | endif() 16 | 17 | add_subdirectory(zip) -------------------------------------------------------------------------------- /src/user/user.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "interface/iuser.h" 4 | 5 | #include "net/extendedsocket.h" 6 | #include "channel/channel.h" 7 | #include "definitions.h" 8 | 9 | class CUser : public IUser 10 | { 11 | public: 12 | CUser(IExtendedSocket* socket, int userID, const std::string& userName); 13 | ~CUser(); 14 | 15 | void SetCurrentChannel(CChannel* channel); 16 | void SetLastChannelServer(CChannelServer* channelServer); 17 | void SetStatus(UserStatus newStatus); 18 | void SetCurrentRoom(IRoom* room); 19 | void SetRoomData(CRoomUser* roomUser); 20 | 21 | UserNetworkConfig_s GetNetworkConfig(); 22 | IExtendedSocket* GetExtendedSocket(); 23 | CChannel* GetCurrentChannel(); 24 | CChannelServer* GetLastChannelServer(); 25 | IRoom* GetCurrentRoom(); 26 | CRoomUser* GetRoomData(); 27 | UserStatus GetStatus(); 28 | bool IsPlaying(); 29 | int GetUptime(); 30 | int GetID(); 31 | std::string GetUsername(); 32 | const char* GetLogName(); 33 | CUserData GetUser(int flag); 34 | CUserCharacter GetCharacter(int lowFlag, int highFlag = 0); 35 | CUserCharacterExtended GetCharacterExtended(int flag); 36 | 37 | int UpdateHolepunch(int portId, const std::string& localIpAddress, int localPort, int externalPort); 38 | void UpdateClientUserInfo(CUserCharacter character); 39 | void UpdateGameName(const std::string& gameName); 40 | int UpdatePoints(int64_t points); 41 | void UpdateCash(int64_t cash); 42 | void UpdateHonorPoints(int honorPoints); 43 | void UpdatePrefix(int prefixID); 44 | void UpdateStat(int battles, int win, int kills, int deaths); 45 | void UpdateLocation(int nation, int city, int town); 46 | void UpdateChatColor(int chatColorID); 47 | void UpdateRank(int leagueID); 48 | void UpdateLevel(int level); 49 | void UpdateExp(int64_t exp); 50 | int UpdatePasswordBoxes(int passwordBoxes); 51 | void UpdateTitles(int slot, int titleID); 52 | void UpdateAchievementList(int titleID); 53 | void UpdateClan(int clanID); 54 | void UpdateTournament(int tournament); 55 | int UpdateBanList(const std::string& gameName, bool remove = false); 56 | void UpdateBanSettings(int settings); 57 | void UpdateNameplate(int nameplateID); 58 | void UpdateZbRespawnEffect(int zbRespawnEffect); 59 | void UpdateKillerMarkEffect(int killerMarkEffect); 60 | 61 | int CheckForLvlUp(int64_t exp); 62 | 63 | void OnTick(); 64 | 65 | bool IsCharacterExists(); 66 | bool CreateCharacter(const std::string& gameName); 67 | 68 | private: 69 | IExtendedSocket* m_pSocket; 70 | 71 | // network data 72 | UserNetworkConfig_s m_NetworkData; 73 | 74 | IRoom* m_pCurrentRoom; 75 | CRoomUser* m_pRoomData; 76 | CChannel* m_pCurrentChannel; 77 | CChannelServer* m_pLastChannelServer; 78 | 79 | UserStatus m_Status; 80 | int m_nUptime; 81 | int m_nID; 82 | std::string m_UserName; 83 | }; -------------------------------------------------------------------------------- /src/user/userfastbuy.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "main.h" 4 | 5 | class CUserFastBuy 6 | { 7 | public: 8 | CUserFastBuy() 9 | { 10 | } 11 | 12 | CUserFastBuy(std::string name, std::vector items) 13 | { 14 | m_Name = name; 15 | m_Items = items; 16 | } 17 | 18 | std::string m_Name; 19 | std::vector m_Items; 20 | }; -------------------------------------------------------------------------------- /src/user/userinventoryitem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class CUserInventoryItem 6 | { 7 | public: 8 | // !! keep argument order! 9 | CUserInventoryItem(); 10 | //CUserInventoryItem(int slot, int count, int inUse, int obtainDate, int expiryDate, int status, int isClanItem, int enhanceLvl, int enhanceExp, int enhanceValue, int paintID, std::vector parts); 11 | CUserInventoryItem(int slot, int itemID, int count, int status, int inUse, int obtainDate, int expiryDate, int isClanItem, int enhanceLvl, int enhanceExp, int enhanceValue, int paintID, std::vector paintIDList, int partSlot1, int partSlot2, int lockStatus); 12 | CUserInventoryItem(int userID, int slot, int itemID, int count, int status, int inUse, int obtainDate, int expiryDate, int isClanItem, int enhanceLvl, int enhanceExp, int enhanceValue, int paintID, std::string paintIDList, int partSlot1, int partSlot2, int lockStatus); 13 | 14 | void Init(int slot, int itemID, int count, int status, int inUse, int obtainDate, int expiryDate, int isClanItem, int enhanceLvl, int enhanceExp, int enhanceValue, int paintID, std::vector paintIDList, int partSlot1, int partSlot2, int lockStatus); 15 | void Reset(); 16 | void PushItem(std::vector& vec, int itemID, int count, int status, int inUse, int obtainDate, int expiryDate, int isClanItem, int enhanceLvl, int enhanceExp, int enhanceValue, int paintID, std::vector paintIDList, int partSlot1, int partSlot2, int lockStatus); 17 | void PushItem(std::vector& vec, CUserInventoryItem& item); 18 | void ConvertDurationToExpiryDate(); 19 | bool IsItemDefault(); 20 | bool IsItemDefault(int itemID); 21 | bool IsItemPseudoDefault(); 22 | bool IsItemPseudoDefault(int itemID); 23 | bool IsItemDefaultOrPseudo(int itemID = 0); 24 | int GetGameSlot() const; 25 | int GetSlot(); 26 | int GameSlotToSlot(int gameSlot); 27 | int GetPartCount() const; 28 | 29 | int m_nSlot; // real slot from DB 30 | int m_nItemID; 31 | int m_nCount; 32 | int m_nInUse; 33 | int m_nObtainDate; 34 | int m_nExpiryDate; 35 | int m_nPaintID; 36 | std::vector m_nPaintIDList; 37 | int m_nStatus; 38 | int m_nEnhancementLevel; 39 | int m_nEnhancementExp; 40 | int m_nEnhanceValue; 41 | int m_nIsClanItem; 42 | int m_nPartSlot1; 43 | int m_nPartSlot2; 44 | int m_nLockStatus; 45 | }; -------------------------------------------------------------------------------- /src/user/userloadout.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JusicP/CSNZ_Server/4859a6e73451ccbfce167b1d28deeb0457468ac3/src/user/userloadout.cpp -------------------------------------------------------------------------------- /src/user/userloadout.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class CUserLoadout 7 | { 8 | public: 9 | CUserLoadout() 10 | { 11 | } 12 | 13 | CUserLoadout(std::vector& slots) 14 | { 15 | items = slots; 16 | } 17 | 18 | std::vector items; 19 | }; 20 | 21 | class CUserBuyMenu 22 | { 23 | public: 24 | CUserBuyMenu() 25 | { 26 | } 27 | 28 | CUserBuyMenu(std::vector& slots) 29 | { 30 | items = slots; 31 | } 32 | 33 | std::vector items; 34 | }; 35 | 36 | class CUserCostumeLoadout 37 | { 38 | public: 39 | CUserCostumeLoadout() 40 | { 41 | m_nHeadCostumeID = 0; 42 | m_nBackCostumeID = 0; 43 | m_nArmCostumeID = 0; 44 | m_nPelvisCostumeID = 0; 45 | m_nFaceCostumeID = 0; 46 | m_nTattooID = 0; 47 | m_nPetCostumeID = 0; 48 | } 49 | 50 | CUserCostumeLoadout(int head, int back, int arm, int pelvis, int face, int tattoo, int pet) 51 | { 52 | m_nHeadCostumeID = head; 53 | m_nBackCostumeID = back; 54 | m_nArmCostumeID = arm; 55 | m_nPelvisCostumeID = pelvis; 56 | m_nFaceCostumeID = face; 57 | m_nTattooID = tattoo; 58 | m_nPetCostumeID = pet; 59 | } 60 | 61 | int m_nHeadCostumeID; 62 | int m_nBackCostumeID; 63 | int m_nArmCostumeID; 64 | int m_nPelvisCostumeID; 65 | int m_nFaceCostumeID; 66 | std::map m_ZombieSkinCostumeID; 67 | int m_nTattooID; 68 | int m_nPetCostumeID; 69 | }; 70 | --------------------------------------------------------------------------------