private void ReceiveHandle(object arg) { var line = arg as String; try { var args = new Answer(line); switch (args.Message) { case "Hello": Reseted?.Invoke(); break; case "dropped": Dropped?.Invoke(int.Parse(args.Values["N"])); break; case "queued": Queued?.Invoke(int.Parse(args.Values["N"])); break; case "started": Started?.Invoke(int.Parse(args.Values["N"])); break; case "completed": Completed?.Invoke(int.Parse(args.Values["N"]), args.Values); break; case "failed": Failed?.Invoke(int.Parse(args.Values["N"]), line); break; case "debug": Debug?.Invoke(line); break; case "error": Error?.Invoke(line); break; default: break; } if (args.Values.ContainsKey("Q")) { SetQ(int.Parse(args.Values["Q"]), int.Parse(args.Values["N"])); } } catch { Logger.Instance.Error(this, "exception", line); } }
private void QueueThreadProc() { while (running) { if (commandsQueue.TryDequeue(out Command cmd)) { Queued?.Invoke(cmd.id); commandsRun.Enqueue(cmd); if (commandsRun.Count >= maxLength) { EmptySlotsEnded?.Invoke(); } SlotsNumberReceived?.Invoke(cmd.id); } Thread.Sleep(10); } }
public void ReceiveMessage(object peer) { NetIncomingMessage message; while ((message = Client.ReadMessage()) != null) { switch (message.MessageType) { case NetIncomingMessageType.Data: var packetType = (int)message.ReadByte(); Packet packet; switch (packetType) { case (int)PacketTypes.Disconnect: packet = new DisconnectPacket(); packet.NetIncomingMessageToPacket(message); Connected?.Invoke(false); break; case (int)PacketTypes.QueueForGame: packet = new QueueForGamePacket(); packet.NetIncomingMessageToPacket(message); Queued?.Invoke(true); break; case (int)PacketTypes.CancelQueueForGame: packet = new CancelQueueForGamePacket(); packet.NetIncomingMessageToPacket(message); Queued?.Invoke(false); break; case (int)PacketTypes.GameFound: packet = new GameFoundPacket(); packet.NetIncomingMessageToPacket(message); ConnectToGameServer((GameFoundPacket)packet); break; default: break; } break; case NetIncomingMessageType.DebugMessage: Debug.Log("Debug Message: " + message.ReadString()); break; case NetIncomingMessageType.WarningMessage: Debug.Log("Warning Message: " + message.ReadString()); break; case NetIncomingMessageType.StatusChanged: var status = (NetConnectionStatus)message.ReadByte(); switch (status) { case NetConnectionStatus.InitiatedConnect: Debug.Log("Initiated contact with server"); break; case NetConnectionStatus.Connected: Connected?.Invoke(true); break; case NetConnectionStatus.Disconnecting: case NetConnectionStatus.Disconnected: Connected?.Invoke(false); break; default: Debug.Log("Unhandled Status Changed type: " + status); break; } break; default: Debug.Log("Unhandled type: " + message.MessageType + " " + message.LengthBytes + "bytes"); break; } Client.Recycle(message); } }
/// <summary> /// Invokes the <see cref="Queued" />-Event /// </summary> protected virtual void OnQueued() { Queued?.Invoke(this, new EventArgs()); }
private void RTSender_Queued(int N) { Logger.Instance.Debug(this, "unlock", "queued"); waitResponse.Set(); Queued?.Invoke(N); }