remove error_code
This commit is contained in:
parent
33eeeb25f8
commit
47e6a14480
@ -1,13 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
类似http的错误码设计
|
|
||||||
0:成功
|
|
||||||
<400: 客户端的错
|
|
||||||
>500: 服务器的错
|
|
||||||
*/
|
|
||||||
enum ErrorCode_e
|
|
||||||
{
|
|
||||||
ERRNO_OK = 0,
|
|
||||||
|
|
||||||
};
|
|
@ -869,6 +869,14 @@ void Player::ProcPrepareItems(const ::google::protobuf::RepeatedField< ::google:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Player::ProcPrepareItems2(const ::google::protobuf::RepeatedPtrField< cs::MFPair >&
|
||||||
|
prepare_items)
|
||||||
|
{
|
||||||
|
for (auto& pair : prepare_items) {
|
||||||
|
AddItem(pair.key(), pair.value());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Player::_CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg)
|
void Player::_CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg)
|
||||||
{
|
{
|
||||||
moving = false;
|
moving = false;
|
||||||
|
@ -82,7 +82,10 @@ class Player : public Human
|
|||||||
void ObstacleInteraction(Obstacle* entity);
|
void ObstacleInteraction(Obstacle* entity);
|
||||||
void LootInteraction(Loot* entity);
|
void LootInteraction(Loot* entity);
|
||||||
void HumanInteraction(Human* hum);
|
void HumanInteraction(Human* hum);
|
||||||
void ProcPrepareItems(const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& prepare_items);
|
void ProcPrepareItems(const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >&
|
||||||
|
prepare_items);
|
||||||
|
void ProcPrepareItems2(const ::google::protobuf::RepeatedPtrField< cs::MFPair >&
|
||||||
|
prepare_items);
|
||||||
|
|
||||||
void _CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg);
|
void _CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg);
|
||||||
void _CMEmote(f8::MsgHdr& hdr, const cs::CMEmote& msg);
|
void _CMEmote(f8::MsgHdr& hdr, const cs::CMEmote& msg);
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
|
|
||||||
#include "constant.h"
|
#include "constant.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "error_code.h"
|
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
|
|
||||||
namespace google
|
namespace google
|
||||||
|
@ -165,6 +165,19 @@ void Room::AddPlayer(Player* hum)
|
|||||||
hum->room = this;
|
hum->room = this;
|
||||||
hum->join_frameno = frame_no;
|
hum->join_frameno = frame_no;
|
||||||
hum->Initialize();
|
hum->Initialize();
|
||||||
|
{
|
||||||
|
cs::SMJoinedNotify notifymsg;
|
||||||
|
notifymsg.set_error_code(0);
|
||||||
|
FillSMJoinedNotify(hum, notifymsg);
|
||||||
|
GGListener::Instance()->SendToClient(hum->socket_handle, 0, notifymsg);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
cs::SMMapInfo notifymsg;
|
||||||
|
notifymsg.set_map_id(map_meta->i->map_id());
|
||||||
|
notifymsg.set_map_width(map_meta->i->map_width());
|
||||||
|
notifymsg.set_map_height(map_meta->i->map_height());
|
||||||
|
GGListener::Instance()->SendToClient(hum->socket_handle, 0, notifymsg);
|
||||||
|
}
|
||||||
uniid_hash_[hum->entity_uniid] = hum;
|
uniid_hash_[hum->entity_uniid] = hum;
|
||||||
moveable_hash_[hum->entity_uniid] = hum;
|
moveable_hash_[hum->entity_uniid] = hum;
|
||||||
accountid_hash_[hum->account_id] = hum;
|
accountid_hash_[hum->account_id] = hum;
|
||||||
|
@ -53,6 +53,10 @@ void RoomMgr::Init()
|
|||||||
if (!map_meta_) {
|
if (!map_meta_) {
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
hum_meta_ = MetaMgr::Instance()->GetPlayer(40001);
|
||||||
|
if (!hum_meta_) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
map_service_ = new MapService();
|
map_service_ = new MapService();
|
||||||
grid_service_ = new GridService();
|
grid_service_ = new GridService();
|
||||||
grid_service_->Init(map_meta_->i->map_width(),
|
grid_service_->Init(map_meta_->i->map_width(),
|
||||||
@ -99,10 +103,7 @@ void RoomMgr::Update(int delta_time)
|
|||||||
|
|
||||||
void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg)
|
void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg)
|
||||||
{
|
{
|
||||||
MetaData::Player* hum_meta = MetaMgr::Instance()->GetPlayer(40001);
|
RoomType_e self_room_type = GetHumanRoomType(msg);
|
||||||
if (!hum_meta) {
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
if (IsLimitJoin()) {
|
if (IsLimitJoin()) {
|
||||||
{
|
{
|
||||||
cs::SMJoinedNotify notifymsg;
|
cs::SMJoinedNotify notifymsg;
|
||||||
@ -110,7 +111,8 @@ void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg)
|
|||||||
GGListener::Instance()->SendToClient(hdr.socket_handle, hdr.seqid, notifymsg);
|
GGListener::Instance()->SendToClient(hdr.socket_handle, hdr.seqid, notifymsg);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
a8::Timer::Instance()->AddDeadLineTimer(1000 * 2,
|
a8::Timer::Instance()->
|
||||||
|
AddDeadLineTimer(1000 * 2,
|
||||||
a8::XParams()
|
a8::XParams()
|
||||||
.SetSender(hdr.socket_handle),
|
.SetSender(hdr.socket_handle),
|
||||||
[] (const a8::XParams& param)
|
[] (const a8::XParams& param)
|
||||||
@ -129,49 +131,16 @@ void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg)
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
RoomType_e self_room_type = GetHumanRoomType(msg);
|
|
||||||
Room* room = GetJoinableRoom(msg, self_room_type);
|
Room* room = GetJoinableRoom(msg, self_room_type);
|
||||||
if (!room) {
|
if (!room) {
|
||||||
room = new Room();
|
|
||||||
room->room_type = self_room_type;
|
|
||||||
room->room_uuid = App::Instance()->NewUuid();
|
|
||||||
room->room_idx = AllocRoomIdx();
|
|
||||||
room->grid_service = grid_service_;
|
|
||||||
room->map_service = map_service_;
|
|
||||||
room->spawn_points = &spawn_points_;
|
|
||||||
room->loots = &loots_;
|
|
||||||
room->buildings = &buildings_;
|
|
||||||
if (GetRoomByUuid(room->room_uuid)) {
|
|
||||||
abort();
|
|
||||||
}
|
}
|
||||||
room->map_meta = map_meta_;
|
Player* hum = PlayerMgr::Instance()->CreatePlayerByCMJoin(hdr.ip_saddr,
|
||||||
room->Init();
|
hdr.socket_handle,
|
||||||
inactive_room_hash_[room->room_uuid] = room;
|
msg);
|
||||||
room_hash_[room->room_uuid] = room;
|
hum->meta = hum_meta_;
|
||||||
}
|
|
||||||
Player* hum = PlayerMgr::Instance()->CreatePlayerByCMJoin(hdr.ip_saddr, hdr.socket_handle, msg);
|
|
||||||
hum->meta = hum_meta;
|
|
||||||
room->AddPlayer(hum);
|
|
||||||
hum->ProcPrepareItems(msg.prepare_items());
|
hum->ProcPrepareItems(msg.prepare_items());
|
||||||
{
|
hum->ProcPrepareItems2(msg.prepare_items2());
|
||||||
for (auto& pair : msg.prepare_items2()) {
|
room->AddPlayer(hum);
|
||||||
hum->AddItem(pair.key(), pair.value());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
cs::SMJoinedNotify notifymsg;
|
|
||||||
notifymsg.set_error_code(0);
|
|
||||||
room->FillSMJoinedNotify(hum, notifymsg);
|
|
||||||
GGListener::Instance()->SendToClient(hdr.socket_handle, hdr.seqid, notifymsg);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
cs::SMMapInfo notifymsg;
|
|
||||||
notifymsg.set_map_id(map_meta_->i->map_id());
|
|
||||||
notifymsg.set_map_width(map_meta_->i->map_width());
|
|
||||||
notifymsg.set_map_height(map_meta_->i->map_height());
|
|
||||||
GGListener::Instance()->SendToClient(hdr.socket_handle, hdr.seqid, notifymsg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int RoomMgr::RoomNum()
|
int RoomMgr::RoomNum()
|
||||||
@ -221,7 +190,7 @@ Room* RoomMgr::GetJoinableRoom(const cs::CMJoin& msg, const RoomType_e self_room
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nullptr;
|
return CreateRoom(self_room_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
Room* RoomMgr::GetRoomByUuid(long long room_uuid)
|
Room* RoomMgr::GetRoomByUuid(long long room_uuid)
|
||||||
@ -525,3 +494,32 @@ int RoomMgr::AllocRoomIdx()
|
|||||||
} while (GetRoomByIdx(++current_room_idx_));
|
} while (GetRoomByIdx(++current_room_idx_));
|
||||||
return current_room_idx_;
|
return current_room_idx_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Room* RoomMgr::CreateRoom(RoomType_e room_type)
|
||||||
|
{
|
||||||
|
int room_idx = AllocRoomIdx();
|
||||||
|
if (room_idx == -1) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
Room* room = new Room();
|
||||||
|
room->room_type = room_type;
|
||||||
|
room->room_uuid = App::Instance()->NewUuid();
|
||||||
|
room->room_idx = AllocRoomIdx();
|
||||||
|
room->grid_service = grid_service_;
|
||||||
|
room->map_service = map_service_;
|
||||||
|
room->spawn_points = &spawn_points_;
|
||||||
|
room->loots = &loots_;
|
||||||
|
room->buildings = &buildings_;
|
||||||
|
if (GetRoomByUuid(room->room_uuid)) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
if (GetRoomByIdx(room->room_idx)) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
room->map_meta = map_meta_;
|
||||||
|
room->Init();
|
||||||
|
inactive_room_hash_[room->room_uuid] = room;
|
||||||
|
room_hash_[room->room_uuid] = room;
|
||||||
|
room_idx_hash_[room->room_idx] = room;
|
||||||
|
return room;
|
||||||
|
}
|
||||||
|
@ -11,6 +11,7 @@ namespace MetaData
|
|||||||
{
|
{
|
||||||
struct Map;
|
struct Map;
|
||||||
struct MapTplThing;
|
struct MapTplThing;
|
||||||
|
struct Player;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace metatable
|
namespace metatable
|
||||||
@ -61,6 +62,7 @@ class RoomMgr : public a8::Singleton<RoomMgr>
|
|||||||
Entity* GetEntityByUniId(int uniid);
|
Entity* GetEntityByUniId(int uniid);
|
||||||
int AllocUniid();
|
int AllocUniid();
|
||||||
int AllocRoomIdx();
|
int AllocRoomIdx();
|
||||||
|
Room* CreateRoom(RoomType_e room_type);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<long long, Room*> inactive_room_hash_;
|
std::map<long long, Room*> inactive_room_hash_;
|
||||||
@ -78,4 +80,6 @@ class RoomMgr : public a8::Singleton<RoomMgr>
|
|||||||
std::vector<MetaData::MapTplThing*> spawn_points_;
|
std::vector<MetaData::MapTplThing*> spawn_points_;
|
||||||
std::vector<MetaData::MapTplThing*> loots_;
|
std::vector<MetaData::MapTplThing*> loots_;
|
||||||
std::vector<Building*> buildings_;
|
std::vector<Building*> buildings_;
|
||||||
|
|
||||||
|
MetaData::Player* hum_meta_;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user