mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-05 06:50:04 +00:00
Rearranged the codebase a little.
* Deleted empty Player.cpp * Moved the helper functions from the obsolete CNStructs.cpp into main.cpp and deleted it * Renamed CombatManager to MobManager, as that will likely become it's main focus soon
This commit is contained in:
parent
5efc8ac089
commit
e03da83ff3
6
Makefile
6
Makefile
@ -30,20 +30,18 @@ CSRC=\
|
|||||||
|
|
||||||
CXXSRC=\
|
CXXSRC=\
|
||||||
src/ChatManager.cpp\
|
src/ChatManager.cpp\
|
||||||
src/CombatManager.cpp\
|
|
||||||
src/CNLoginServer.cpp\
|
src/CNLoginServer.cpp\
|
||||||
src/CNProtocol.cpp\
|
src/CNProtocol.cpp\
|
||||||
src/CNShardServer.cpp\
|
src/CNShardServer.cpp\
|
||||||
src/CNShared.cpp\
|
src/CNShared.cpp\
|
||||||
src/CNStructs.cpp\
|
|
||||||
src/Database.cpp\
|
src/Database.cpp\
|
||||||
src/Defines.cpp\
|
src/Defines.cpp\
|
||||||
src/main.cpp\
|
src/main.cpp\
|
||||||
src/MissionManager.cpp\
|
src/MissionManager.cpp\
|
||||||
|
src/MobManager.cpp\
|
||||||
src/NanoManager.cpp\
|
src/NanoManager.cpp\
|
||||||
src/ItemManager.cpp\
|
src/ItemManager.cpp\
|
||||||
src/NPCManager.cpp\
|
src/NPCManager.cpp\
|
||||||
src/Player.cpp\
|
|
||||||
src/PlayerManager.cpp\
|
src/PlayerManager.cpp\
|
||||||
src/settings.cpp\
|
src/settings.cpp\
|
||||||
src/TransportManager.cpp\
|
src/TransportManager.cpp\
|
||||||
@ -64,7 +62,6 @@ CXXHDR=\
|
|||||||
src/contrib/INIReader.hpp\
|
src/contrib/INIReader.hpp\
|
||||||
src/contrib/JSON.hpp\
|
src/contrib/JSON.hpp\
|
||||||
src/ChatManager.hpp\
|
src/ChatManager.hpp\
|
||||||
src/CombatManager.hpp\
|
|
||||||
src/CNLoginServer.hpp\
|
src/CNLoginServer.hpp\
|
||||||
src/CNProtocol.hpp\
|
src/CNProtocol.hpp\
|
||||||
src/CNShardServer.hpp\
|
src/CNShardServer.hpp\
|
||||||
@ -75,6 +72,7 @@ CXXHDR=\
|
|||||||
src/contrib/INIReader.hpp\
|
src/contrib/INIReader.hpp\
|
||||||
src/contrib/JSON.hpp\
|
src/contrib/JSON.hpp\
|
||||||
src/MissionManager.hpp\
|
src/MissionManager.hpp\
|
||||||
|
src/MobManager.hpp\
|
||||||
src/NanoManager.hpp\
|
src/NanoManager.hpp\
|
||||||
src/ItemManager.hpp\
|
src/ItemManager.hpp\
|
||||||
src/NPCManager.hpp\
|
src/NPCManager.hpp\
|
||||||
|
@ -167,7 +167,7 @@ void CNSocket::step() {
|
|||||||
// we aren't reading a packet yet, try to start looking for one
|
// we aren't reading a packet yet, try to start looking for one
|
||||||
int recved = recv(sock, (buffer_t*)readBuffer, sizeof(int32_t), 0);
|
int recved = recv(sock, (buffer_t*)readBuffer, sizeof(int32_t), 0);
|
||||||
if (!SOCKETERROR(recved)) {
|
if (!SOCKETERROR(recved)) {
|
||||||
// we got out packet size!!!!
|
// we got our packet size!!!!
|
||||||
readSize = *((int32_t*)readBuffer);
|
readSize = *((int32_t*)readBuffer);
|
||||||
// sanity check
|
// sanity check
|
||||||
if (readSize > CN_PACKET_BUFFER_SIZE) {
|
if (readSize > CN_PACKET_BUFFER_SIZE) {
|
||||||
|
@ -1,31 +0,0 @@
|
|||||||
#include "CNStructs.hpp"
|
|
||||||
#include <chrono>
|
|
||||||
|
|
||||||
std::string U16toU8(char16_t* src) {
|
|
||||||
try {
|
|
||||||
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>,char16_t> convert;
|
|
||||||
return convert.to_bytes(src);
|
|
||||||
} catch(const std::exception& e) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// returns number of char16_t that was written at des
|
|
||||||
size_t U8toU16(std::string src, char16_t* des) {
|
|
||||||
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>,char16_t> convert;
|
|
||||||
std::u16string tmp = convert.from_bytes(src);
|
|
||||||
|
|
||||||
// copy utf16 string to buffer
|
|
||||||
memcpy(des, tmp.c_str(), sizeof(char16_t) * tmp.length());
|
|
||||||
des[tmp.length()] = '\0';
|
|
||||||
|
|
||||||
return tmp.length();
|
|
||||||
}
|
|
||||||
|
|
||||||
time_t getTime() {
|
|
||||||
using namespace std::chrono;
|
|
||||||
|
|
||||||
milliseconds value = duration_cast<milliseconds>((time_point_cast<milliseconds>(high_resolution_clock::now())).time_since_epoch());
|
|
||||||
|
|
||||||
return (time_t)value.count();
|
|
||||||
}
|
|
@ -13,7 +13,7 @@ void ChatManager::chatHandler(CNSocket* sock, CNPacketData* data) {
|
|||||||
if (data->size != sizeof(sP_CL2FE_REQ_SEND_FREECHAT_MESSAGE))
|
if (data->size != sizeof(sP_CL2FE_REQ_SEND_FREECHAT_MESSAGE))
|
||||||
return; // malformed packet
|
return; // malformed packet
|
||||||
sP_CL2FE_REQ_SEND_FREECHAT_MESSAGE* chat = (sP_CL2FE_REQ_SEND_FREECHAT_MESSAGE*)data->buf;
|
sP_CL2FE_REQ_SEND_FREECHAT_MESSAGE* chat = (sP_CL2FE_REQ_SEND_FREECHAT_MESSAGE*)data->buf;
|
||||||
PlayerView plr = PlayerManager::players[sock];
|
PlayerView& plr = PlayerManager::players[sock];
|
||||||
|
|
||||||
// send to client
|
// send to client
|
||||||
INITSTRUCT(sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC, resp);
|
INITSTRUCT(sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC, resp);
|
||||||
@ -27,11 +27,12 @@ void ChatManager::chatHandler(CNSocket* sock, CNPacketData* data) {
|
|||||||
otherSock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC));
|
otherSock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatManager::menuChatHandler(CNSocket* sock, CNPacketData* data) {
|
void ChatManager::menuChatHandler(CNSocket* sock, CNPacketData* data) {
|
||||||
if (data->size != sizeof(sP_CL2FE_REQ_SEND_MENUCHAT_MESSAGE))
|
if (data->size != sizeof(sP_CL2FE_REQ_SEND_MENUCHAT_MESSAGE))
|
||||||
return; // malformed packet
|
return; // malformed packet
|
||||||
sP_CL2FE_REQ_SEND_MENUCHAT_MESSAGE* chat = (sP_CL2FE_REQ_SEND_MENUCHAT_MESSAGE*)data->buf;
|
sP_CL2FE_REQ_SEND_MENUCHAT_MESSAGE* chat = (sP_CL2FE_REQ_SEND_MENUCHAT_MESSAGE*)data->buf;
|
||||||
PlayerView plr = PlayerManager::players[sock];
|
PlayerView& plr = PlayerManager::players[sock];
|
||||||
|
|
||||||
// send to client
|
// send to client
|
||||||
INITSTRUCT(sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC, resp);
|
INITSTRUCT(sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC, resp);
|
||||||
@ -45,6 +46,7 @@ void ChatManager::menuChatHandler(CNSocket* sock, CNPacketData* data) {
|
|||||||
otherSock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC));
|
otherSock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatManager::emoteHandler(CNSocket* sock, CNPacketData* data) {
|
void ChatManager::emoteHandler(CNSocket* sock, CNPacketData* data) {
|
||||||
if (data->size != sizeof(sP_CL2FE_REQ_PC_AVATAR_EMOTES_CHAT))
|
if (data->size != sizeof(sP_CL2FE_REQ_PC_AVATAR_EMOTES_CHAT))
|
||||||
return; // ignore the malformed packet
|
return; // ignore the malformed packet
|
||||||
@ -52,7 +54,7 @@ void ChatManager::emoteHandler(CNSocket* sock, CNPacketData* data) {
|
|||||||
// you can dance with friends!!!!!!!!
|
// you can dance with friends!!!!!!!!
|
||||||
|
|
||||||
sP_CL2FE_REQ_PC_AVATAR_EMOTES_CHAT* emote = (sP_CL2FE_REQ_PC_AVATAR_EMOTES_CHAT*)data->buf;
|
sP_CL2FE_REQ_PC_AVATAR_EMOTES_CHAT* emote = (sP_CL2FE_REQ_PC_AVATAR_EMOTES_CHAT*)data->buf;
|
||||||
PlayerView plr = PlayerManager::players[sock];
|
PlayerView& plr = PlayerManager::players[sock];
|
||||||
|
|
||||||
// send to client
|
// send to client
|
||||||
INITSTRUCT(sP_FE2CL_REP_PC_AVATAR_EMOTES_CHAT, resp);
|
INITSTRUCT(sP_FE2CL_REP_PC_AVATAR_EMOTES_CHAT, resp);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#include "CombatManager.hpp"
|
#include "MobManager.hpp"
|
||||||
#include "PlayerManager.hpp"
|
#include "PlayerManager.hpp"
|
||||||
#include "NPCManager.hpp"
|
#include "NPCManager.hpp"
|
||||||
#include "ItemManager.hpp"
|
#include "ItemManager.hpp"
|
||||||
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
void CombatManager::init() {
|
void MobManager::init() {
|
||||||
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_ATTACK_NPCs, pcAttackNpcs);
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_ATTACK_NPCs, pcAttackNpcs);
|
||||||
|
|
||||||
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_COMBAT_BEGIN, combatBegin);
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_COMBAT_BEGIN, combatBegin);
|
||||||
@ -14,7 +14,7 @@ void CombatManager::init() {
|
|||||||
REGISTER_SHARD_PACKET(P_CL2FE_DOT_DAMAGE_ONOFF, dotDamageOnOff);
|
REGISTER_SHARD_PACKET(P_CL2FE_DOT_DAMAGE_ONOFF, dotDamageOnOff);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CombatManager::pcAttackNpcs(CNSocket *sock, CNPacketData *data) {
|
void MobManager::pcAttackNpcs(CNSocket *sock, CNPacketData *data) {
|
||||||
sP_CL2FE_REQ_PC_ATTACK_NPCs* pkt = (sP_CL2FE_REQ_PC_ATTACK_NPCs*)data->buf;
|
sP_CL2FE_REQ_PC_ATTACK_NPCs* pkt = (sP_CL2FE_REQ_PC_ATTACK_NPCs*)data->buf;
|
||||||
Player *plr = PlayerManager::getPlayer(sock);
|
Player *plr = PlayerManager::getPlayer(sock);
|
||||||
|
|
||||||
@ -82,11 +82,11 @@ void CombatManager::pcAttackNpcs(CNSocket *sock, CNPacketData *data) {
|
|||||||
s->sendPacket((void*)respbuf, P_FE2CL_PC_ATTACK_NPCs, resplen);
|
s->sendPacket((void*)respbuf, P_FE2CL_PC_ATTACK_NPCs, resplen);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CombatManager::combatBegin(CNSocket *sock, CNPacketData *data) {} // stub
|
void MobManager::combatBegin(CNSocket *sock, CNPacketData *data) {} // stub
|
||||||
void CombatManager::combatEnd(CNSocket *sock, CNPacketData *data) {} // stub
|
void MobManager::combatEnd(CNSocket *sock, CNPacketData *data) {} // stub
|
||||||
void CombatManager::dotDamageOnOff(CNSocket *sock, CNPacketData *data) {} // stub
|
void MobManager::dotDamageOnOff(CNSocket *sock, CNPacketData *data) {} // stub
|
||||||
|
|
||||||
void CombatManager::giveReward(CNSocket *sock) {
|
void MobManager::giveReward(CNSocket *sock) {
|
||||||
Player *plr = PlayerManager::getPlayer(sock);
|
Player *plr = PlayerManager::getPlayer(sock);
|
||||||
|
|
||||||
const size_t resplen = sizeof(sP_FE2CL_REP_REWARD_ITEM) + sizeof(sItemReward);
|
const size_t resplen = sizeof(sP_FE2CL_REP_REWARD_ITEM) + sizeof(sItemReward);
|
@ -4,7 +4,7 @@
|
|||||||
#include "CNShared.hpp"
|
#include "CNShared.hpp"
|
||||||
#include "CNShardServer.hpp"
|
#include "CNShardServer.hpp"
|
||||||
|
|
||||||
namespace CombatManager {
|
namespace MobManager {
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
void pcAttackNpcs(CNSocket *sock, CNPacketData *data);
|
void pcAttackNpcs(CNSocket *sock, CNPacketData *data);
|
@ -1 +0,0 @@
|
|||||||
#include "Player.hpp"
|
|
36
src/main.cpp
36
src/main.cpp
@ -2,7 +2,7 @@
|
|||||||
#include "CNShardServer.hpp"
|
#include "CNShardServer.hpp"
|
||||||
#include "PlayerManager.hpp"
|
#include "PlayerManager.hpp"
|
||||||
#include "ChatManager.hpp"
|
#include "ChatManager.hpp"
|
||||||
#include "CombatManager.hpp"
|
#include "MobManager.hpp"
|
||||||
#include "ItemManager.hpp"
|
#include "ItemManager.hpp"
|
||||||
#include "MissionManager.hpp"
|
#include "MissionManager.hpp"
|
||||||
#include "NanoManager.hpp"
|
#include "NanoManager.hpp"
|
||||||
@ -21,6 +21,7 @@
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
#endif
|
#endif
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <chrono>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
// HACK
|
// HACK
|
||||||
@ -92,7 +93,7 @@ int main() {
|
|||||||
TableData::init();
|
TableData::init();
|
||||||
PlayerManager::init();
|
PlayerManager::init();
|
||||||
ChatManager::init();
|
ChatManager::init();
|
||||||
CombatManager::init();
|
MobManager::init();
|
||||||
ItemManager::init();
|
ItemManager::init();
|
||||||
MissionManager::init();
|
MissionManager::init();
|
||||||
NanoManager::init();
|
NanoManager::init();
|
||||||
@ -117,3 +118,34 @@ int main() {
|
|||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// helper functions
|
||||||
|
|
||||||
|
std::string U16toU8(char16_t* src) {
|
||||||
|
try {
|
||||||
|
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>,char16_t> convert;
|
||||||
|
return convert.to_bytes(src);
|
||||||
|
} catch(const std::exception& e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns number of char16_t that was written at des
|
||||||
|
size_t U8toU16(std::string src, char16_t* des) {
|
||||||
|
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>,char16_t> convert;
|
||||||
|
std::u16string tmp = convert.from_bytes(src);
|
||||||
|
|
||||||
|
// copy utf16 string to buffer
|
||||||
|
memcpy(des, tmp.c_str(), sizeof(char16_t) * tmp.length());
|
||||||
|
des[tmp.length()] = '\0';
|
||||||
|
|
||||||
|
return tmp.length();
|
||||||
|
}
|
||||||
|
|
||||||
|
time_t getTime() {
|
||||||
|
using namespace std::chrono;
|
||||||
|
|
||||||
|
milliseconds value = duration_cast<milliseconds>((time_point_cast<milliseconds>(high_resolution_clock::now())).time_since_epoch());
|
||||||
|
|
||||||
|
return (time_t)value.count();
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user