internal RoomManager(uint maxusernum, 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_ = maxusernum;
     user_pool_ = new UserPool();
     dispatcher_ = new Dispatcher();
     thread_tick_interval_ = tick_interval;
     connector_ = conn;
 }
 internal bool Init(uint tick_interval, uint room_count,
     UserPool userpool, Connector conn)
 {
     tick_interval_ = tick_interval;
     max_room_count_ = room_count;
     room_pool_.Init(max_room_count_);
     user_pool_ = userpool;
     connector_ = conn;
     preactive_room_count_ = 0;
     LogSys.Log(LOG_TYPE.DEBUG, "thread {0} init ok.", cur_thread_id_);
     return true;
 }
        private void Init(string[] args)
        {
            m_NameHandleCallback = this.OnNameHandleChanged;
            m_MsgCallback = this.OnMessage;
            m_MsgResultCallback = this.OnMessageResultCallback;
            m_CmdCallback = this.OnCommand;
            m_LogHandler = this.OnCenterLog;
            CenterClientApi.SetCenterLogHandler(m_LogHandler);
            CenterClientApi.Init("roomserver", args.Length, args, m_NameHandleCallback, m_MsgCallback, m_MsgResultCallback, m_CmdCallback);

            Console.WriteLine("begin init roomserver...");
            HomePath.InitHomePath();

            bool ret = LogSys.Init("./config/logconfig.xml");
            System.Diagnostics.Debug.Assert(ret);

            last_tick_time_ = TimeUtility.GetLocalMilliseconds();
            last_send_roominfo_time_ = last_tick_time_;
            is_continue_register_ = true;
            channel_ = new PBChannel(BigworldAndRoomServerMessageEnum2Type.Query, BigworldAndRoomServerMessageEnum2Type.Query);
            channel_.DefaultServiceName = "Lobby";
            lobby_connector_ = new Connector(channel_);

            server_ip_ = "127.0.0.1";
            server_port_ = 9528;

            InitConfig();

            GlobalVariables.Instance.IsClient = false;

            string key = "防君子不防小人";
            byte[] xor = Encoding.UTF8.GetBytes(key);

            ResourceReadProxy.OnReadAsArray = ((string filePath) => {
                byte[] buffer = null;
                try {
                    buffer = File.ReadAllBytes(filePath);
                } catch (Exception e) {
                    LogSys.Log(LOG_TYPE.ERROR, "Exception:{0}\n{1}", e.Message, e.StackTrace);
                    return null;
                }
                return buffer;
            });
            LogSystem.OnOutput += (Log_Type type, string msg) => {
                switch (type) {
                    case Log_Type.LT_Debug:
                        LogSys.Log(LOG_TYPE.DEBUG, msg);
                        break;
                    case Log_Type.LT_Info:
                        LogSys.Log(LOG_TYPE.INFO, msg);
                        break;
                    case Log_Type.LT_Warn:
                        LogSys.Log(LOG_TYPE.WARN, msg);
                        break;
                    case Log_Type.LT_Error:
                    case Log_Type.LT_Assert:
                        LogSys.Log(LOG_TYPE.ERROR, msg);
                        break;
                }
            };

            LoadData();

            LogSys.Log(LOG_TYPE.DEBUG, "room server init ip: {0}  port: {1}", server_ip_, server_port_);

            uint tick_interval = 33;
            room_mgr_ = new RoomManager(1280, c_thread_count, c_per_thread_room_count, tick_interval, lobby_connector_);
            room_mgr_.Init(room_server_name_);
            IOManager.Instance.Init((int)server_port_);
            room_mgr_.StartRoomThread();
            AiViewManager.Instance.Init();
            SceneLogicViewManager.Instance.Init();

            ServerStorySystem.StaticInit();
            GameFramework.GmCommands.GmStorySystem.StaticInit();

            channel_.Register<Msg_LR_ReplyRegisterRoomServer>(HandleReplyRegisterRoomServer);
            room_mgr_.RegisterMsgHandler(channel_);

            LogSys.Log(LOG_TYPE.DEBUG, "room server init ok.");
        }
示例#4
0
 internal bool Init(int room_id, int scene_type, UserPool userpool, Connector conn)
 {
     LogSys.Log(LOG_TYPE.INFO, "[0] Room.Init {0} scene {1}", room_id, scene_type);
     cur_room_id_ = room_id;
     user_pool_ = userpool;
     connector_ = conn;
     can_close_time_ = 0;
     m_ActiveScene = m_ScenePool.NewScene();
     LogSys.Log(LOG_TYPE.INFO, "[1] Room.Init {0} scene {1}", room_id, scene_type);
     m_ActiveScene.SetRoom(this);
     //场景数据加载由加载线程执行(注:场景没有加载完成,场景状态仍然是sleep,Scene.Tick不会有实际的动作)
     SceneLoadThread.Instance.QueueAction(m_ActiveScene.LoadData, scene_type);
     m_ActiveTime = TimeUtility.GetLocalMicroseconds();
     CurrentState = RoomState.Active;
     m_CanFinish = false;
     LogSys.Log(LOG_TYPE.DEBUG, "Room Initialize: {0}  Scene: {1}", room_id, scene_type);
     return true;
 }