/// <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); } } }
/// <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); }
public async Task AddRequest(MessengerRequest request, int targetId) { if (!Requests.ContainsKey(request.Id)) { await _dao.AddPlayerFriendRequestAsync(request.Id, targetId); Requests.Add(request.Id, request); } }
//добавление запроса в узел 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; } }
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)); }
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); } }
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); } }
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()); }
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(); } } } }
/// <summary> /// Получает, находится ли запрос с указанным идентификатором в процессе обработки /// </summary> /// <param name="requestID">Идентифкатор запроса</param> /// <returns></returns> public bool ContainsRequest(DownloadRequestID requestID) { return(Requests.ContainsKey(requestID)); }