public static void Switch(ISession session, byte[] recv)
        {
            ServerListRequest request = new ServerListRequest();

            if (!request.Parse(recv))
            {
                LogWriter.ToLog(LogEventLevel.Error, ErrorMessage.GetErrorMsg(SBErrorCode.Parse));
                return;
            }
            switch (request.UpdateOption)
            {
            case SBServerListUpdateOption.NoServerList:
                new NoServerListHandler(request, session, recv).Handle();
                break;

            case SBServerListUpdateOption.GeneralRequest:
                new GeneralRequestHandler(request, session, recv).Handle();
                break;

            case SBServerListUpdateOption.SendGroups:
                new SendGroupsHandler(request, session, recv).Handle();
                break;

            case SBServerListUpdateOption.LimitResultCount:
                break;

            case SBServerListUpdateOption.PushUpdates:
                // worms 3d send this after join group room
                // we should send adhoc servers which are in this room to worms3d
                new PushUpdatesHandler(request, session, recv).Handle();
                break;
            }
        }
예제 #2
0
        public void ServerListTest()
        {
            var raw = new byte[] { 0x00, 0x55,
                                   0x00, //command name
                                   0x01, 0x03, 0x00, 0x00, 0x00,
                                   0x00, 0x67, 0x6d, 0x74, 0x65, 0x73, 0x74, 0x00,
                                   0x67, 0x6d, 0x74, 0x65, 0x73, 0x74, 0x00, 0x6e,
                                   0x29, 0x29, 0x34, 0x31, 0x58, 0x4d, 0x36, 0x00,
                                   0x5c, 0x68, 0x6f, 0x73, 0x74, 0x6e, 0x61, 0x6d,
                                   0x65, 0x5c, 0x67, 0x61, 0x6d, 0x65, 0x74, 0x79,
                                   0x70, 0x65, 0x5c, 0x6d, 0x61, 0x70, 0x6e, 0x61,
                                   0x6d, 0x65, 0x5c, 0x6e, 0x75, 0x6d, 0x70, 0x6c,
                                   0x61, 0x79, 0x65, 0x72, 0x73, 0x5c, 0x6d, 0x61,
                                   0x78, 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x73,
                                   0x00, 0x00, 0x00, 0x00, 0x00 };
            var request = new ServerListRequest(raw);

            request.Parse();
            Assert.Equal(RequestType.ServerListRequest, request.CommandName);

            raw = new byte[] { 0x00, 0x58,
                               0x00,
                               0x01, 0x03, 0x00, 0x00, 0x00, 0x00, 0x67, 0x6d, 0x74, 0x65, 0x73, 0x74, 0x00, 0x67, 0x6d, 0x74, 0x65, 0x73, 0x74, 0x00, 0x42, 0x46, 0x5d, 0x6c, 0x6b, 0x22, 0x2c, 0x35, 0x31, 0x32, 0x33, 0x00, 0x5c, 0x68, 0x6f, 0x73, 0x74, 0x6e, 0x61, 0x6d, 0x65, 0x5c, 0x6e, 0x75, 0x6d, 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x73, 0x5c, 0x6d, 0x61, 0x78, 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x73, 0x5c, 0x6d, 0x61, 0x70, 0x6e, 0x61, 0x6d, 0x65, 0x5c, 0x67, 0x61, 0x6d, 0x65, 0x74, 0x79, 0x70, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00 };
            request = new ServerListRequest(raw);
            request.Parse();
        }
        private static void ServerListCommand(object command)
        {
            ServerListRequest  request  = (ServerListRequest)command;
            ServerListResponse response = new ServerListResponse();
            string             address  = request.GetAddress();

            // Decode JSON stream
            try
            {
                string jsonStream;
                using (WebClient client = new WebClient())
                    jsonStream = Encoding.ASCII.GetString(client.DownloadData(address));

                response = Json.LoadStream <ServerListResponse>(jsonStream);
            }
            catch (Exception e)
            {
                Console.WriteLine("ServerList error: {0}", e.Message);
            }

            if (!String.IsNullOrEmpty(response.Token))
            {
                Console.WriteLine("Private token: {0}", response.Token);
                token = response.Token;
            }

            Console.WriteLine("Status: {0}; Reason: {1}", response.Status, response.Reason);
        }
예제 #4
0
 void Awake()
 {
     serverListRequest = GetComponent <ServerListRequest>();
     for (int i = 0; i < GridContent.transform.childCount; i++)
     {
         ServerItem server = GridContent.transform.GetChild(i).GetComponent <ServerItem>();
         server.ServerId = i;
     }
     facade.PlayMusic("Menu");
 }
예제 #5
0
        private static bool ParseActions(string[] args)
        {
            return(Parser.Default.ParseArguments <ConfigOption, ServerListOption>(args)
                   .MapResult(
                       (ConfigOption opt) =>
            {
                var handler = ServicesContainer.Container.Resolve <IHandler <ConfigurationRequest> >();
                var request = new ConfigurationRequest
                {
                    UserName = opt.UserName,
                    Password = opt.Password
                };

                try
                {
                    handler.HandleAsync(request).Wait();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    return false;
                }

                return true;
            },
                       (ServerListOption opt) =>
            {
                var handler = ServicesContainer.Container.Resolve <IHandler <ServerListRequest> >();
                var request = new ServerListRequest
                {
                    Local = opt.Local
                };

                try
                {
                    handler.HandleAsync(request).Wait();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    return false;
                }

                return true;
            },
                       errors =>
            {
                var logger = ServicesContainer.Container.Resolve <ILogger>();

                errors.ToList().ForEach(err => logger.Error("Parsing error {error}", err));

                return true;
            }));
        }
        public void Should_Return_List_Of_Servers()
        {
            var serverListRequest = new ServerListRequest {
                Token = _token
            };

            var response = _playgroundClient.GetServerList(serverListRequest).Result;

            Assert.IsNotNull(response);
            Assert.IsNotNull(response.Servers);
            CollectionAssert.IsNotEmpty(response.Servers);
        }
예제 #7
0
        public async Task <ServerListResponse> GetServerList(ServerListRequest serverListRequest)
        {
            var client  = new RestClient($"{_baseUri}/servers");
            var request = new RestRequest(Method.GET);

            request.AddHeader("content-type", "application/json");
            request.AddHeader("Authorization", "Bearer " + serverListRequest.Token);
            var response = await client.ExecuteTaskAsync <IList <ServerInfo> >(request); // does not work with array:/

            var data = HandleResponse <IList <ServerInfo> >(response);

            return(new ServerListResponse(data));
        }
예제 #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ServerListRequestThreadSafeWriter" /> struct.
 /// </summary>
 /// <param name="connection">The connection.</param>
 public ServerListRequestThreadSafeWriter(IConnection connection)
 {
     this.connection = connection;
     Monitor.Enter(this.connection);
     try
     {
         // Initialize header and default values
         var span = this.Span;
         span.Clear();
         _ = new ServerListRequest(span);
     }
     catch (InvalidOperationException)
     {
         Monitor.Exit(this.connection);
         throw;
     }
 }
예제 #9
0
 public GeneralRequestHandler(ServerListRequest request, ISession client, byte[] recv) : base(request, client, recv)
 {
 }
예제 #10
0
 public PushUpdatesHandler(ServerListRequest request, ISession client, byte[] recv) : base(request, client, recv)
 {
 }
예제 #11
0
 public async Task <ServerListResponse> GetServerList(ServerListRequest serverListRequest)
 {
     return(await _playgroundClient.GetServerList(serverListRequest));
 }
 public SendGroupsHandler(ServerListRequest request, ISession client, byte[] recv) : base(request, client, recv)
 {
 }
예제 #13
0
 public UpdateOptionHandlerBase(ServerListRequest request, ISession session, byte[] recv) : base(session, recv)
 {
     _request  = request;
     _dataList = new List <byte>();
 }