remove error_code

This commit is contained in:
aozhiwei 2020-05-21 13:21:48 +08:00
parent 33eeeb25f8
commit 47e6a14480
7 changed files with 78 additions and 66 deletions

View File

@ -1,13 +0,0 @@
#pragma once
/*
http的错误码设计
0
<400:
>500:
*/
enum ErrorCode_e
{
ERRNO_OK = 0,
};

View File

@ -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)
{
moving = false;

View File

@ -82,7 +82,10 @@ class Player : public Human
void ObstacleInteraction(Obstacle* entity);
void LootInteraction(Loot* entity);
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 _CMEmote(f8::MsgHdr& hdr, const cs::CMEmote& msg);

View File

@ -9,7 +9,6 @@
#include "constant.h"
#include "types.h"
#include "error_code.h"
#include "global.h"
namespace google

View File

@ -165,6 +165,19 @@ void Room::AddPlayer(Player* hum)
hum->room = this;
hum->join_frameno = frame_no;
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;
moveable_hash_[hum->entity_uniid] = hum;
accountid_hash_[hum->account_id] = hum;

View File

@ -53,6 +53,10 @@ void RoomMgr::Init()
if (!map_meta_) {
abort();
}
hum_meta_ = MetaMgr::Instance()->GetPlayer(40001);
if (!hum_meta_) {
abort();
}
map_service_ = new MapService();
grid_service_ = new GridService();
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)
{
MetaData::Player* hum_meta = MetaMgr::Instance()->GetPlayer(40001);
if (!hum_meta) {
abort();
}
RoomType_e self_room_type = GetHumanRoomType(msg);
if (IsLimitJoin()) {
{
cs::SMJoinedNotify notifymsg;
@ -110,13 +111,14 @@ void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg)
GGListener::Instance()->SendToClient(hdr.socket_handle, hdr.seqid, notifymsg);
}
{
a8::Timer::Instance()->AddDeadLineTimer(1000 * 2,
a8::XParams()
.SetSender(hdr.socket_handle),
[] (const a8::XParams& param)
{
GGListener::Instance()->ForceCloseChildSocket(param.sender);
});
a8::Timer::Instance()->
AddDeadLineTimer(1000 * 2,
a8::XParams()
.SetSender(hdr.socket_handle),
[] (const a8::XParams& param)
{
GGListener::Instance()->ForceCloseChildSocket(param.sender);
});
}
a8::UdpLog::Instance()->Warning("room is full! accountid:%s max_mainloop_rundelay:%d "
"room_num:%d player_num:%d online_num:%d",
@ -129,49 +131,16 @@ void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg)
});
return;
}
RoomType_e self_room_type = GetHumanRoomType(msg);
Room* room = GetJoinableRoom(msg, self_room_type);
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_;
room->Init();
inactive_room_hash_[room->room_uuid] = room;
room_hash_[room->room_uuid] = room;
}
Player* hum = PlayerMgr::Instance()->CreatePlayerByCMJoin(hdr.ip_saddr, hdr.socket_handle, msg);
hum->meta = hum_meta;
room->AddPlayer(hum);
Player* hum = PlayerMgr::Instance()->CreatePlayerByCMJoin(hdr.ip_saddr,
hdr.socket_handle,
msg);
hum->meta = hum_meta_;
hum->ProcPrepareItems(msg.prepare_items());
{
for (auto& pair : msg.prepare_items2()) {
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);
}
hum->ProcPrepareItems2(msg.prepare_items2());
room->AddPlayer(hum);
}
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)
@ -525,3 +494,32 @@ int RoomMgr::AllocRoomIdx()
} while (GetRoomByIdx(++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;
}

View File

@ -11,6 +11,7 @@ namespace MetaData
{
struct Map;
struct MapTplThing;
struct Player;
}
namespace metatable
@ -61,6 +62,7 @@ class RoomMgr : public a8::Singleton<RoomMgr>
Entity* GetEntityByUniId(int uniid);
int AllocUniid();
int AllocRoomIdx();
Room* CreateRoom(RoomType_e room_type);
private:
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*> loots_;
std::vector<Building*> buildings_;
MetaData::Player* hum_meta_;
};