Exemplo n.º 1
0
        /// <summary>
        /// Request to join a room
        /// </summary>
        /// <param name="roomID">Requested room ID</param>
        /// <param name="player">Player who request it</param>
        private void JoinRequest(int roomID, Player player)
        {
            Room r = Room.Search(roomID, rooms);

            if (r != null)
            {
                if (r.Player2 == null)
                {
                    if (!Requests.ContainsKey(r.Player1))
                    {
                        Requests.Add(r.Player1, new System.Collections.Generic.Queue <Player>());
                        Requests[r.Player1].Enqueue(player);
                    }
                    else
                    {
                        Requests[r.Player1].Enqueue(player);
                    }
                    string s = "request;" + player.Name;
                    Send(Connections[r.Player1], s);
                }
                else
                {
                    string s = "sorry;";
                    Send(Connections[player], s);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets an IMessage based on it's data (byte array)
        /// See the Frame object for more information on what the bytes are represent
        /// </summary>
        /// <param name="pData"></param>
        /// <returns>IMessage</returns>
        public IMessage GetMessage(byte[] pData)
        {
            Frame objFrame = new Frame(pData);
            Type  objType  = null;

            try {
                if (objFrame.Type != MessageType.Response)
                {
                    if (Requests.ContainsKey(objFrame.Name))
                    {
                        objType = Requests[objFrame.Name];
                    }
                }
                else
                {
                    if (Responses.ContainsKey(objFrame.Name))
                    {
                        objType = Responses[objFrame.Name];
                    }
                }
            } catch {
                Log.Error("Invalid data received, ignoring...");
                return(null);
            }
            if (objType != null)
            {
                return(MessagingFactory.Converter.GetMessage(objType, objFrame.Data));
            }
            return(null);
        }
Exemplo n.º 3
0
        public async Task AddRequest(MessengerRequest request, int targetId)
        {
            if (!Requests.ContainsKey(request.Id))
            {
                await _dao.AddPlayerFriendRequestAsync(request.Id, targetId);

                Requests.Add(request.Id, request);
            }
        }
Exemplo n.º 4
0
        //добавление запроса в узел
        public void AddRequestToNode(string request, int phraseFreq, int accurateFreq)
        {
            int freq = accurateFreq == 0 ? phraseFreq : accurateFreq;

            if (!Requests.ContainsKey(request))
            {
                Requests.Add(request, freq);
            }
            else if (Requests[request] < freq)
            {
                Requests[request] = freq;
            }
        }
Exemplo n.º 5
0
 private byte[] _WriteTo(LSRequestMessage message)
 {
     _SerialNo = (ushort)((int)_SerialNo++ % 255 + 1);
     message?.SetSerial(_SerialNo);
     if (Requests.ContainsKey(_SerialNo))
     {
         Requests[_SerialNo] = message;
     }
     else
     {
         Requests.Add(_SerialNo, message);
     }
     return(_GetBytes(message));
 }
Exemplo n.º 6
0
        internal SyncObject RegisterRequest(ref int RequestId)
        {
            lock (Requests)
            {
                SyncObject syncObj = new SyncObject(this);
                FastRandom rnd     = new FastRandom();

                do
                {
                    RequestId = rnd.Next();
                }while (Requests.ContainsKey(RequestId));

                Requests.Add(RequestId, syncObj);

                return(syncObj);
            }
        }
Exemplo n.º 7
0
        public InterfacePrototype GetSharedClass <InterfacePrototype>(string name, params object[] RemoteArgs)
        {
            lock (InitializedClasses)
            {
                SyncObject syncObject = null;
                lock (Requests)
                {
                    int RequestId = 0;

                    RequestId = GetNextRandomInteger();
                    while (Requests.ContainsKey(RequestId))
                    {
                        RequestId = GetNextRandomInteger();
                    }

                    syncObject = new SyncObject(this);
                    Requests.Add(RequestId, syncObject);
                    Send(new MsgGetSharedClass(name, RemoteArgs, RequestId));
                }

                ReturnResult result = syncObject.Wait <ReturnResult>(null, 30000); //wait for response
                if (result == null)
                {
                    throw new Exception("A timeout occured");
                }
                if (result.ExceptionOccured)
                {
                    throw new Exception(result.exceptionMessage);
                }
                if (result.ReturnValue == null)
                {
                    throw new Exception("The shared class \"" + name + "\" could not be found in the remote client");
                }

                SharedClass c = (SharedClass)result.ReturnValue;
                c.Client = this;
                InterfacePrototype tmp = DynClassCreator.CreateDynamicClass <InterfacePrototype>(c);

                InitializedClasses.Add(c.SharedId, c);
                return(tmp);
            }
        }
Exemplo n.º 8
0
        public TResponse Execute <TRequest, TResponse>(Func <T, Func <TRequest, CallOptions, TResponse> > func, TRequest request, bool throwException = false)
            where TRequest : class, IMessage <TRequest>, new()
            where TResponse : class, IMessage <TResponse>, new()
        {
            var requestName = GetRequestKey <TRequest>();

            if (Requests.ContainsKey(requestName))
            {
                Requests[requestName]++;
            }
            else
            {
                Requests.TryAdd(requestName, 1);
            }

            if (clientMock != null)
            {
                return(func(clientMock)(request, new CallOptions()));
            }

            return(new TResponse());
        }
Exemplo n.º 9
0
        void ReadTCP(IAsyncResult result)
        {
            try
            {
                try
                {
                    string response = "";

                    response = Encoding.ASCII.GetString(ReadBuffer, 0, 512);

                    response = response.Replace("\0", "");
                    Parent.DumpLog(response, 10);
                    if (response != "")
                    {
                        try
                        {
                            response = response.Substring(0, response.IndexOf("\n"));

                            YLBasicResponse tmprespo = json.JsonDeserialize <YLBasicResponse>(response);
                            if (Requests.ContainsKey(tmprespo.id))
                            {
                                switch (Requests[tmprespo.id])
                                {
                                case "read_user_coin_data": ReadUser(response); break;

                                case "create_bet": ProcessBet(response); break;

                                case "read_current_seed": read_current_seed(response); break;

                                case "read_seed": read_current_seed(response); break;

                                case "create_seed": create_seed(response); break;

                                case "patch_seed": patch_seed(response); break;

                                case "create_withdrawal": create_withdrawal(response); break;

                                case "ping": ping(response); break;
                                }
                                Requests.Remove(tmprespo.id);
                            }
                        }
                        catch (Exception e)
                        {
                            Parent.updateStatus("Error: " + response);
                        }
                    }
                }
                catch (Exception e)
                {
                    if (!apiclient.Connected)
                    {
                        if (!inauth)
                        {
                            Auth();
                        }
                    }
                }
                ReadBuffer = new byte[512];
                if (apiclient.Connected)
                {
                    try
                    {
                        sslStream.EndRead(result);
                        sslStream.BeginRead(ReadBuffer, 0, 512, ReadTCP, sslStream);
                    }
                    catch
                    {
                        if (!apiclient.Connected)
                        {
                            if (!inauth)
                            {
                                Auth();
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (!apiclient.Connected)
                {
                    if (!inauth)
                    {
                        Auth();
                    }
                }
            }
        }
Exemplo n.º 10
0
 /// <summary>
 /// Получает, находится ли запрос с указанным идентификатором в процессе обработки
 /// </summary>
 /// <param name="requestID">Идентифкатор запроса</param>
 /// <returns></returns>
 public bool ContainsRequest(DownloadRequestID requestID)
 {
     return(Requests.ContainsKey(requestID));
 }