OpenFusion/src/PlayerManager.hpp

54 lines
1.7 KiB
C++
Raw Normal View History

#pragma once
2020-08-18 20:42:30 +00:00
#include "Player.hpp"
#include "core/Core.hpp"
#include "servers/CNShardServer.hpp"
#include "Chunking.hpp"
2020-08-18 20:42:30 +00:00
2020-09-17 22:45:43 +00:00
#include <utility>
2020-08-18 20:42:30 +00:00
#include <map>
#include <list>
struct WarpLocation;
2020-08-18 20:42:30 +00:00
namespace PlayerManager {
2020-11-17 23:16:16 +00:00
extern std::map<CNSocket*, Player*> players;
2020-08-18 20:42:30 +00:00
void init();
void removePlayer(CNSocket* key);
2020-11-18 00:07:04 +00:00
void updatePlayerPosition(CNSocket* sock, int X, int Y, int Z, uint64_t I, int angle);
void updatePlayerPositionForWarp(CNSocket* sock, int X, int Y, int Z, uint64_t inst);
2020-09-17 22:45:43 +00:00
2020-10-12 16:55:41 +00:00
void sendPlayerTo(CNSocket* sock, int X, int Y, int Z, uint64_t I);
void sendPlayerTo(CNSocket* sock, int X, int Y, int Z);
Player *getPlayer(CNSocket* key);
std::string getPlayerName(Player *plr, bool id=true);
bool isAccountInUse(int accountId);
void exitDuplicate(int accountId);
Player *getPlayerFromID(int32_t iID);
CNSocket *getSockFromID(int32_t iID);
CNSocket *getSockFromName(std::string firstname, std::string lastname);
CNSocket *getSockFromAny(int by, int id, int uid, std::string firstname, std::string lastname);
WarpLocation *getRespawnPoint(Player *plr);
void sendToViewable(CNSocket *sock, void* buf, uint32_t type, size_t size);
// TODO: unify this under the new Entity system
template<class T>
void sendToViewable(CNSocket *sock, T& pkt, uint32_t type) {
Player* plr = getPlayer(sock);
for (auto it = plr->viewableChunks.begin(); it != plr->viewableChunks.end(); it++) {
Chunk* chunk = *it;
for (const EntityRef& ref : chunk->entities) {
2022-04-13 19:56:12 +00:00
if (ref.kind != EntityKind::PLAYER || ref.sock == sock)
continue;
ref.sock->sendPacket(pkt, type);
}
}
}
2020-08-18 20:42:30 +00:00
}