コード例 #1
0
        public MatchSeverProxy(int id, KChannel channel, ServertoDS servertods)
        {
            this.id                    = id;
            this.channel               = channel;
            this.servertods            = servertods;
            this.channel.ondisconnect += () => {
                // Console.WriteLine("ondisconnect");
                MatchSeverProxy matchserverproxy;
                bool            b = servertods.matchserverproxys.TryRemove(id, out matchserverproxy);
                if (b)
                {
                    Logger.log("remove a MatchSeverProxy sucessfully");
                }
                else
                {
                    Logger.log("this should not happen when remove a MatchSeverProxy");
                }
            };
            this.channel.onUserLevelReceivedCompleted += (ref byte[] buffer) =>
            {
                switch ((CMDLoadBalanceServer)buffer[0])
                {
                case CMDLoadBalanceServer.CREATEDS:
                    int roomid = BitConverter.ToInt32(buffer, 1);
                    servertods.GetABestDSM().DS_request(this.id, roomid, CMD.NEW_DS);
                    Logger.log("CMDLoadBalanceServer.CREATEDS MatchSeverid : " + id + "--roomid--" + roomid);
                    break;

                case CMDLoadBalanceServer.CREATEDSV1:
                    roomid = BitConverter.ToInt32(buffer, 1);
                    servertods.GetABestDSM().DS_request(this.id, roomid, CMD.NEW_DSV1);
                    Logger.log("CMDLoadBalanceServer.CREATEDS MatchSeverid : " + id + "--roomid--" + roomid);
                    break;

                case CMDLoadBalanceServer.DESTROY:
                    roomid = BitConverter.ToInt32(buffer, 1);
                    servertods.GetABestDSM().DS_request(this.id, roomid, CMD.KILL_DS);
                    Logger.log("CMDLoadBalanceServer.DESTROY");
                    break;

                case CMDLoadBalanceServer.DESTROYV1:
                    roomid = BitConverter.ToInt32(buffer, 1);
                    servertods.GetABestDSM().DS_request(this.id, roomid, CMD.KILL_DSV1);
                    Logger.log("CMDLoadBalanceServer.DESTROY");
                    break;

                default:
                    break;
                }
            };
        }
コード例 #2
0
        public DSMproxy(KChannel channel, ServertoDS servertods)
        {
            this.channel               = channel;
            this.servertods            = servertods;
            this.channel.ondisconnect += () => {
                this.servertods.DSMchannels.Remove(this);
                // Console.WriteLine("ondisconnect");
                Logger.log("ondisconnect");
            };
            this.channel.onUserLevelReceivedCompleted += (ref byte[] buffer) =>
            {
#if RTT
                var str = System.Text.Encoding.UTF8.GetString(buffer);
                //Console.WriteLine(str);
                ASCIIEncoding asen    = new ASCIIEncoding();
                byte[]        buffer1 = asen.GetBytes(str + "server");
                send(ref buffer1);
#else
                switch ((CMD)buffer[0])
                {
                case CMD.WANIP:
                    wan = new byte[buffer.Length - 1];
                    Array.Copy(buffer, 1, wan, 0, wan.Length);
                    break;

                case CMD.NEW_DS:
                    int             matchserverid = BitConverter.ToInt32(buffer, 1);
                    int             roomid        = BitConverter.ToInt32(buffer, 5);
                    int             port          = BitConverter.ToInt32(buffer, 9);
                    MatchSeverProxy matchserverproxy;
                    servertods.matchserverproxys.TryGetValue(matchserverid, out matchserverproxy);
                    byte[] sumbuffer = new byte[8 + wan.Length];
                    sumbuffer.WriteTo(0, roomid);
                    sumbuffer.WriteTo(4, port);
                    Array.Copy(wan, 0, sumbuffer, 8, wan.Length);
                    matchserverproxy.send((byte)CMDLoadBalanceServer.CREATEDS, sumbuffer);
                    Logger.log("matchserverid :" + matchserverid + " -- roomid :" + roomid + " -- port : " + port);
                    break;

                case CMD.NEW_DSV1:
                    matchserverid = BitConverter.ToInt32(buffer, 1);
                    roomid        = BitConverter.ToInt32(buffer, 5);
                    port          = BitConverter.ToInt32(buffer, 9);
                    servertods.matchserverproxys.TryGetValue(matchserverid, out matchserverproxy);
                    sumbuffer = new byte[8 + wan.Length];
                    sumbuffer.WriteTo(0, roomid);
                    sumbuffer.WriteTo(4, port);
                    Array.Copy(wan, 0, sumbuffer, 8, wan.Length);
                    matchserverproxy.send((byte)CMDLoadBalanceServer.CREATEDSV1, sumbuffer);
                    Logger.log("matchserverid :" + matchserverid + " -- roomid :" + roomid + " -- port : " + port);
                    break;

                case CMD.KILL_DS:
                    break;

                default:
                    break;
                }
#endif
            };
            send((byte)CMD.WANIP, BitConverter.GetBytes(0));
        }