Skip to content

Commit

Permalink
Version 1.42
Browse files Browse the repository at this point in the history
  • Loading branch information
m-byte918 committed Nov 16, 2019
1 parent 2fc0ac2 commit 0eb0b7c
Show file tree
Hide file tree
Showing 73 changed files with 2,137 additions and 1,138 deletions.
18 changes: 11 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
/.vs
/logs
/.git
/.vs

/Run/CMake*
/Run/installed
/Run/logs
/Run/AgarOSS*
/Run/*.dll
/Run/Makefile

/x64
/Debug
OgarCPP
/OgarCpp.vcxproj.user
/Release
/Run/vcpkg
/AgarOSS.vcxproj.user
6 changes: 3 additions & 3 deletions OgarCpp.sln → AgarOSS.sln
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27703.2026
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OgarCpp", "OgarCpp.vcxproj", "{FE95AABC-5FD5-43B1-97CA-32C1C33B95E7}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AgarOSS", "AgarOSS.vcxproj", "{FE95AABC-5FD5-43B1-97CA-32C1C33B95E7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -12,8 +12,8 @@ Global
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FE95AABC-5FD5-43B1-97CA-32C1C33B95E7}.Debug|x64.ActiveCfg = Release|x64
{FE95AABC-5FD5-43B1-97CA-32C1C33B95E7}.Debug|x64.Build.0 = Release|x64
{FE95AABC-5FD5-43B1-97CA-32C1C33B95E7}.Debug|x64.ActiveCfg = Debug|x64
{FE95AABC-5FD5-43B1-97CA-32C1C33B95E7}.Debug|x64.Build.0 = Debug|x64
{FE95AABC-5FD5-43B1-97CA-32C1C33B95E7}.Debug|x86.ActiveCfg = Debug|Win32
{FE95AABC-5FD5-43B1-97CA-32C1C33B95E7}.Debug|x86.Build.0 = Debug|Win32
{FE95AABC-5FD5-43B1-97CA-32C1C33B95E7}.Release|x64.ActiveCfg = Release|x64
Expand Down
38 changes: 31 additions & 7 deletions OgarCpp.vcxproj → AgarOSS.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,29 @@
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{FE95AABC-5FD5-43B1-97CA-32C1C33B95E7}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
<ProjectName>OgarCpp</ProjectName>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<ProjectName>AgarOSS</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand All @@ -70,6 +70,13 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>$(SolutionDir)\Run\</OutDir>
<IntDir>$(Platform)\$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>$(SolutionDir)\Run\</OutDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
Expand Down Expand Up @@ -105,13 +112,27 @@
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalIncludeDirectories>C:\Users\ASUS\Desktop\AgarOSS-GitHub\AgarOSS\Run\installed\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<Optimization>MaxSpeed</Optimization>
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
</ClCompile>
<Link>
<AdditionalLibraryDirectories>C:\Users\ASUS\Desktop\AgarOSS-GitHub\AgarOSS\Run\installed\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalIncludeDirectories>C:\Users\ASUS\Desktop\AgarOSS-GitHub\AgarOSS\Run\installed\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>LIBUS_NO_SSL</PreprocessorDefinitions>
<DisableSpecificWarnings>4100</DisableSpecificWarnings>
</ClCompile>
<Link>
<AdditionalLibraryDirectories>C:\Users\ASUS\Desktop\AgarOSS-GitHub\AgarOSS\Run\installed\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>libuv.lib;uSockets.lib;zlib.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AssemblyDebug>true</AssemblyDebug>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Connection\PacketHandler.cpp" />
Expand All @@ -135,7 +156,6 @@
<ClCompile Include="modules\Logger.cpp" />
<ClCompile Include="Player\PlayerBot.cpp" />
<ClCompile Include="Protocol\Protocol.cpp" />
<ClCompile Include="Settings.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Connection\PacketHandler.hpp" />
Expand Down Expand Up @@ -178,6 +198,10 @@
</ItemGroup>
<ItemGroup>
<None Include="README.md" />
<None Include="Settings.json" />
</ItemGroup>
<ItemGroup>
<Text Include="CMakeLists.txt" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
28 changes: 28 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
cmake_minimum_required(VERSION 3.0.2)

project(AgarOSS)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/Run)

# -Wunknown-pragmas: disabled because visual studio
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -O3 -g -Wall -Wno-unknown-pragmas -Wno-unused-variable")

# Not using ssl or compression (yet)
add_definitions(-DLIBUS_NO_SSL -DUWS_NO_ZLIB)

file(GLOB AgarOSS_Source
"*.cpp"
"Protocol/*.cpp"
"Player/*.cpp"
"Modules/*.cpp"
"Game/*.cpp"
"Entities/*.cpp"
"Connection/*.cpp"
)

# Disable warnings from uWS headers
include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/Run/installed/include)
link_directories(${CMAKE_SOURCE_DIR}/Run/installed/lib)

link_libraries(uSockets pthread)
add_executable(${CMAKE_PROJECT_NAME} ${AgarOSS_Source})
41 changes: 39 additions & 2 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,41 @@
# Changelog
### v1.42
- Fixed bug where server could send packets from players without a defined protocol
- Players connecting with protocols < 4 now defaults to protocol 4
- Some tweaks to entity typing system
- Fixed memory management issues with shared pointers
- Some optimizations with entity and player updating
- Players are no longer updated once disconnected
- Playercells no longer autosplit while force merging
- Settings are now loaded from JSON file [#11](https://github.com/m-byte918/AgarOSS/issues/11)
- Added leaderboard with `game_leaderboardLength` config
- Added `player_skinNameTags` config and removed `player_cellRemoveTime` config
- Refactored & reduced some of `map`'s methods
- Added methods to `Buffer` class to read/write UTF8 & Unicode strings without the `wstring` type
- Added `kick` command
- Implemented playerbots with MultiOgar AI (for now..)
- Fixed minions having incorrect skin names
- Fixed crash with `setname` command
- Fixed bug where ejected cells spawned by the `replace` command were intangible
- Added current game tick and average player score to `debug` command
- Added `clampX` & `clampY` methods to `Vec2` class for spectator viewbox
- Added `apt update` to `install_uws.sh`
- Added `contains` method to QuadTree (mostly for debugging purposes)
- Moving entities are now updated in reverse order to reduce cell switching
- Added startup graphics
- Fixed seemingly random crash caused by clearing a buffer that does not exist
- `setmass` command now sets absolute mass of the player instead of the mass of each cell
- Minions no longer respawn unless their owner is in-game
- Small refactoring to logger
- Added logName, logFolder, logBackupFolder configs
- Added cmake support
- Added pstring command to print debug information about a player
- Added server playerbots config
- Added server minionsperplayer config
- Combined install_uws.bat into compile.bat and made it actually work
- Combined install_uws.sh into compile.sh and made it actually work
- Other optimizations and performance improvements
---
### v1.07
- Added `server_host` configuration
- Implemented minions with Q controls
Expand All @@ -22,14 +59,14 @@
- Added vanilla feature where orphaned playercells remain on the map for all eternity
- Fixed excess newlines in console output on linux
- Fixed crash on server shutdown due to players being deleted before entities
- Refactored and reogranized `Commands` class
- Refactored and reorganized `Commands` class
- Added aliases for some commands
- Changed command format from `command(args...)` to `command <args>...` and removed case sensitivity
- Added ability to execute player commands on groups of players using `-p`, `-b`, and `-m` flags
- Reformatted `help` command
- Added `pause`, `minion`, `setname`, `setskin`, `spawnmass`, `explode`, `speed`, `color`, `split`, and `replace` commands
- Added `install_uws.sh` to aid in importing the uWebSockets library for linux
- Fixed compiling on Windows [#10](https://github.com/Megabyte918/OgarCpp/issues/10)
- Fixed compiling on Windows [#10](https://github.com/m-byte918/AgarOSS/issues/10)
- Spelling & grammar corrections
- Other optimizations and performance improvements
---
Expand Down
98 changes: 55 additions & 43 deletions Connection/PacketHandler.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#include "PacketHandler.hpp"
#pragma warning(push, 0)
#include <uwebsockets/App.h>
#pragma warning(pop)
#include "../Game/Map.hpp"
#include "../Game/Game.hpp"
#include "../Player/Player.hpp"
Expand Down Expand Up @@ -27,79 +30,84 @@ PacketHandler::PacketHandler(Player *owner) :

void PacketHandler::sendPacket(Buffer &buffer) const {
const std::vector<unsigned char> &buf = buffer.getBuffer();
if (buf.empty() || !player->socket || player->socket->isClosed())
if (buf.empty() || !player->socket)
return;
player->socket->send(reinterpret_cast<const char *>(buf.data()), buf.size(), uWS::BINARY);
player->socket->send(std::string_view((char*)&buf[0], buf.size()), uWS::BINARY);
buffer.clear();
}

void PacketHandler::onPacket(std::vector<unsigned char> &packet) {
Buffer buffer(packet);

// Process OpCode
switch ((OpCode)buffer.readUInt8()) {
case OpCode::SPAWN:
onSpawn(buffer.readStr());
break;
case OpCode::SPECTATE:
onSpectate();
break;
case OpCode::SET_TARGET:
onTarget({ (double)buffer.readInt32_LE(), (double)buffer.readInt32_LE() });
break;
case OpCode::SPLIT:
onSplit();
break;
case OpCode::QKEY_PRESSED:
onQKey();
break;
case OpCode::EJECT:
onEject();
break;
case OpCode::CAPTCHA_RESPONSE:
Logger::info("Captcha Response packet received.");
break;
case OpCode::PONG:
Logger::info("Pong packet received.");
break;
case OpCode::ESTABLISH_CONNECTION:
onEstablishedConnection(buffer.readUInt32_LE());
break;
case OpCode::CONNECTION_KEY:
onConnectionKey();
break;
case OpCode::SPAWN:
if (player->state() != PlayerState::PLAYING) {
if (player->protocolNum < 6)
player->setFullName(buffer.readStrNull_UCS2(), true);
else
player->setFullName(buffer.readStrNull_UTF8());
player->onSpawn();
}
break;
case OpCode::SPECTATE:
onSpectate();
break;
case OpCode::FACEBOOK_DATA:
break;
case OpCode::SET_TARGET:
onTarget({ (double)buffer.readInt32_LE(), (double)buffer.readInt32_LE() });
break;
case OpCode::SPLIT:
onSplit();
break;
case OpCode::QKEY_PRESSED:
onQKey();
break;
case OpCode::QKEY_RELEASED:
break;
case OpCode::EJECT:
onEject();
break;
case OpCode::CAPTCHA_RESPONSE:
Logger::info("Captcha Response packet received.");
break;
case OpCode::MOBILE_DATA:
break;
case OpCode::PONG:
Logger::info("Pong packet received.");
break;
case OpCode::ESTABLISH_CONNECTION:
onEstablishedConnection(buffer.readUInt32_LE());
break;
case OpCode::CONNECTION_KEY:
onConnectionKey();
break;
}
}

void PacketHandler::onSpawn(std::string name) const noexcept {
Logger::info("Spawn packet received.");
player->onSpawn(name);
}

void PacketHandler::onSpectate() const noexcept {
Logger::info("Spectate packet received.");
player->onSpectate();
}
void PacketHandler::onTarget(const Vec2 &mouse) const noexcept {
//Logger::info("Set Target packet received.");
player->onTarget(mouse);
}
void PacketHandler::onSplit() const noexcept {
player->onSplit();
}
void PacketHandler::onQKey() const noexcept {
//Logger::info("Q keypress packet received.");
player->onQKey();
}
void PacketHandler::onEject() const noexcept {
player->onEject();
}
void PacketHandler::onEstablishedConnection(const unsigned &protocol) const noexcept {
void PacketHandler::onEstablishedConnection(unsigned protocol) const noexcept {
Logger::info("Establish Connection packet received.");
Logger::info("Protocol version: " + std::to_string(protocol));
if (protocol < cfg::server_minSupportedProtocol ||
protocol > cfg::server_maxSupportedProtocol) {
player->socket->close(1002, "Unsupported protocol");
player->socket->end(1002, "Unsupported protocol");
return;
}
switch (protocol) {
Expand All @@ -118,9 +126,13 @@ void PacketHandler::onEstablishedConnection(const unsigned &protocol) const noex
case 16: { player->protocol = new Protocol_16(player); break; }
case 17: { player->protocol = new Protocol_17(player); break; }
case 18: { player->protocol = new Protocol_18(player); break; }
default: { player->protocol = new Protocol(player); }
default: {
player->protocol = new Protocol_4(player);
Logger::warn("Protocol assumed as 4.");
}
}
player->protocolNum = protocol;
player->server->clients.push_back(player);
}
void PacketHandler::onConnectionKey() const noexcept {
Logger::info("Connection Key packet received.");
Expand Down
Loading

0 comments on commit 0eb0b7c

Please sign in to comment.