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=\
|
||||
src/ChatManager.cpp\
|
||||
src/CombatManager.cpp\
|
||||
src/CNLoginServer.cpp\
|
||||
src/CNProtocol.cpp\
|
||||
src/CNShardServer.cpp\
|
||||
src/CNShared.cpp\
|
||||
src/CNStructs.cpp\
|
||||
src/Database.cpp\
|
||||
src/Defines.cpp\
|
||||
src/main.cpp\
|
||||
src/MissionManager.cpp\
|
||||
src/MobManager.cpp\
|
||||
src/NanoManager.cpp\
|
||||
src/ItemManager.cpp\
|
||||
src/NPCManager.cpp\
|
||||
src/Player.cpp\
|
||||
src/PlayerManager.cpp\
|
||||
src/settings.cpp\
|
||||
src/TransportManager.cpp\
|
||||
@ -64,7 +62,6 @@ CXXHDR=\
|
||||
src/contrib/INIReader.hpp\
|
||||
src/contrib/JSON.hpp\
|
||||
src/ChatManager.hpp\
|
||||
src/CombatManager.hpp\
|
||||
src/CNLoginServer.hpp\
|
||||
src/CNProtocol.hpp\
|
||||
src/CNShardServer.hpp\
|
||||
@ -75,6 +72,7 @@ CXXHDR=\
|
||||
src/contrib/INIReader.hpp\
|
||||
src/contrib/JSON.hpp\
|
||||
src/MissionManager.hpp\
|
||||
src/MobManager.hpp\
|
||||
src/NanoManager.hpp\
|
||||
src/ItemManager.hpp\
|
||||
src/NPCManager.hpp\
|
||||
|
@ -167,7 +167,7 @@ void CNSocket::step() {
|
||||
// we aren't reading a packet yet, try to start looking for one
|
||||
int recved = recv(sock, (buffer_t*)readBuffer, sizeof(int32_t), 0);
|
||||
if (!SOCKETERROR(recved)) {
|
||||
// we got out packet size!!!!
|
||||
// we got our packet size!!!!
|
||||
readSize = *((int32_t*)readBuffer);
|
||||
// sanity check
|
||||
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))
|
||||
return; // malformed packet
|
||||
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
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
void ChatManager::menuChatHandler(CNSocket* sock, CNPacketData* data) {
|
||||
if (data->size != sizeof(sP_CL2FE_REQ_SEND_MENUCHAT_MESSAGE))
|
||||
return; // malformed packet
|
||||
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
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
void ChatManager::emoteHandler(CNSocket* sock, CNPacketData* data) {
|
||||
if (data->size != sizeof(sP_CL2FE_REQ_PC_AVATAR_EMOTES_CHAT))
|
||||
return; // ignore the malformed packet
|
||||
@ -52,7 +54,7 @@ void ChatManager::emoteHandler(CNSocket* sock, CNPacketData* data) {
|
||||
// you can dance with friends!!!!!!!!
|
||||
|
||||
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
|
||||
INITSTRUCT(sP_FE2CL_REP_PC_AVATAR_EMOTES_CHAT, resp);
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "CombatManager.hpp"
|
||||
#include "MobManager.hpp"
|
||||
#include "PlayerManager.hpp"
|
||||
#include "NPCManager.hpp"
|
||||
#include "ItemManager.hpp"
|
||||
@ -6,7 +6,7 @@
|
||||
|
||||
#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_COMBAT_BEGIN, combatBegin);
|
||||
@ -14,7 +14,7 @@ void CombatManager::init() {
|
||||
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;
|
||||
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);
|
||||
}
|
||||
|
||||
void CombatManager::combatBegin(CNSocket *sock, CNPacketData *data) {} // stub
|
||||
void CombatManager::combatEnd(CNSocket *sock, CNPacketData *data) {} // stub
|
||||
void CombatManager::dotDamageOnOff(CNSocket *sock, CNPacketData *data) {} // stub
|
||||
void MobManager::combatBegin(CNSocket *sock, CNPacketData *data) {} // stub
|
||||
void MobManager::combatEnd(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);
|
||||
|
||||
const size_t resplen = sizeof(sP_FE2CL_REP_REWARD_ITEM) + sizeof(sItemReward);
|
@ -4,7 +4,7 @@
|
||||
#include "CNShared.hpp"
|
||||
#include "CNShardServer.hpp"
|
||||
|
||||
namespace CombatManager {
|
||||
namespace MobManager {
|
||||
void init();
|
||||
|
||||
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 "PlayerManager.hpp"
|
||||
#include "ChatManager.hpp"
|
||||
#include "CombatManager.hpp"
|
||||
#include "MobManager.hpp"
|
||||
#include "ItemManager.hpp"
|
||||
#include "MissionManager.hpp"
|
||||
#include "NanoManager.hpp"
|
||||
@ -21,6 +21,7 @@
|
||||
#include <thread>
|
||||
#endif
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
#include <signal.h>
|
||||
|
||||
// HACK
|
||||
@ -92,7 +93,7 @@ int main() {
|
||||
TableData::init();
|
||||
PlayerManager::init();
|
||||
ChatManager::init();
|
||||
CombatManager::init();
|
||||
MobManager::init();
|
||||
ItemManager::init();
|
||||
MissionManager::init();
|
||||
NanoManager::init();
|
||||
@ -117,3 +118,34 @@ int main() {
|
||||
#endif
|
||||
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