Пример #1
0
    public void DispatchToServer(int connect_id)
    {
        ServerInfo server_info = this.connect_id_to_server_info[connect_id];

        foreach (KeyValuePair <int, ServerInfo> pair in this.connect_id_to_server_info)
        {
            RSDispatchServer protocol;
            if (pair.Key != connect_id)
            {
                //把刚注册的服务器信息发送给其他服务器
                protocol            = new RSDispatchServer();
                protocol.ConnectId  = server_info.ConnectId;
                protocol.ServerId   = server_info.ServerId;
                protocol.ServerType = server_info.ServerType;
                foreach (int scene_id in server_info.SceneIdList)
                {
                    protocol.SceneIdList.Add(scene_id);
                }
                this.socket.SendToServer(protocol, pair.Key);
            }

            //把其他服务器信息发送给刚注册的服务器
            protocol            = new RSDispatchServer();
            protocol.ConnectId  = pair.Value.ConnectId;
            protocol.ServerId   = pair.Value.ServerId;
            protocol.ServerType = pair.Value.ServerType;
            foreach (int scene_id in pair.Value.SceneIdList)
            {
                protocol.SceneIdList.Add(scene_id);
            }
            this.socket.SendToServer(protocol, connect_id);
        }
    }
Пример #2
0
    public override void Handle(IMessage data, int connect_id, int addition, List <int> player_id_list)
    {
        short msg_id = Protocol.GetMsgId(data);

        switch (msg_id)
        {
        case MsgCode.RS_DispatchServer:
        {
            RSDispatchServer protocol      = data as RSDispatchServer;
            List <int>       scene_id_list = new List <int>();
            foreach (int scene_id in protocol.SceneIdList)
            {
                scene_id_list.Add(scene_id);
            }
            Server.GetInstance().RegisterServer(connect_id, protocol.ServerId, protocol.ServerType, scene_id_list);
        }
        break;

        case MsgCode.SS_RemoteCall:
        {
            SSRemoteCall protocol    = data as SSRemoteCall;
            JObject      json        = JObject.Parse(protocol.Data.ToStringUtf8());
            JObject      result_json = this.remote_handler.Handle(protocol.RemoteId, json);
            if (protocol.CallbackId > 0)
            {
                SSRemoteResult message = new SSRemoteResult();
                message.Data         = ByteString.CopyFromUtf8(result_json.ToString());
                message.ToServerId   = protocol.FromServerId;
                message.FromServerId = Server.GetInstance().GetServerInfo().ServerId;
                message.CallbackId   = protocol.CallbackId;
                Server.GetInstance().GetSocket().SendToServer(message, connect_id);
            }
        }
        break;

        case MsgCode.SS_RemoteResult:
        {
            SSRemoteResult protocol = data as SSRemoteResult;
            JObject        json     = JsonConvert.DeserializeObject <JObject>(protocol.Data.ToStringUtf8());
            Server.GetInstance().RemoteResult(json, protocol.FromServerId, protocol.CallbackId);
        }
        break;

        default:
        {
            Server.GetInstance().DispatchMsg(data, connect_id, addition, player_id_list);
        }
        break;
        }
    }