internal RoomManager(uint thread_amount, uint room_amount) { thread_amount_ = thread_amount; room_amount_ = room_amount; roomthread_list_ = new RoomThread[thread_amount]; user_pool_size_ = thread_amount * room_amount * 3; user_pool_ = new UserPool(); thread_tick_interval_ = 50; }
private void HandleUserRelive(Msg_LR_UserReLive msg, PBChannel channel, int handle, uint seq) { int ix = GetActiveRoomThreadIndex(msg.RoomID); if (ix >= 0) { RoomThread roomThread = roomthread_list_[ix]; roomThread.QueueAction(roomThread.HandleUserRelive, msg); } }
internal RoomManager(uint thread_amount, uint room_amount, uint tick_interval, Connector conn) { thread_amount_ = thread_amount; room_amount_ = room_amount; roomthread_list_ = new RoomThread[thread_amount]; user_pool_size_ = thread_amount * room_amount * 3; user_pool_ = new UserPool(); dispatcher_ = new Dispatcher(); thread_tick_interval_ = tick_interval; connector_ = conn; }
internal bool Init() { lock_obj_ = new object(); active_rooms_ = new Dictionary <int, int>(); user_pool_.Init(user_pool_size_); // 初始化房间线程 for (int i = 0; i < thread_amount_; ++i) { roomthread_list_[i] = new RoomThread(this); roomthread_list_[i].Init(thread_tick_interval_, room_amount_, user_pool_, connector_); } return(true); }
private void HandleReconnectUser(Msg_LR_ReconnectUser urMsg, PBChannel channel, int handle, uint seq) { int ix = GetActiveRoomThreadIndex(urMsg.RoomID); if (ix < 0) { Msg_RL_ReplyReconnectUser.Builder replyBuilder = Msg_RL_ReplyReconnectUser.CreateBuilder(); replyBuilder.SetUserGuid(urMsg.UserGuid); replyBuilder.SetRoomID(urMsg.RoomID); replyBuilder.SetIsSuccess(false); channel.Send(replyBuilder.Build()); } else { RoomThread roomThread = roomthread_list_[ix]; roomThread.QueueAction(roomThread.HandleReconnectUser, urMsg, channel, handle, seq); } }
internal bool ActiveRoom(int roomid, int scenetype, User[] users) { int thread_id = GetIdleThread(); if (thread_id < 0) { LogSys.Log(LOG_TYPE.ERROR, "all room are using, active room failed!"); foreach (User u in users) { LogSys.Log(LOG_TYPE.INFO, "FreeUser {0} for {1} {2}, [RoomManager.ActiveRoom]", u.LocalID, u.Guid, u.GetKey()); user_pool_.FreeUser(u.LocalID); } return(false); } RoomThread roomThread = roomthread_list_[thread_id]; AddActiveRoom(roomid, thread_id); roomThread.PreActiveRoom(); LogSys.Log(LOG_TYPE.INFO, "queue active room {0} scene {1} thread {2} for {3} users", roomid, scenetype, thread_id, users.Length); roomThread.QueueAction(roomThread.ActiveRoom, roomid, scenetype, users); return(true); }