private async void AcceptMessageUDP() { if (enabled) { //Await message object acceptedObject = await standardizedUDP.ReadObject(); //Check for error if (acceptedObject == null) { //Error has occured Disable(); return; } else { AcceptMessageUDP(); } if (acceptedObject is IClientMessage) { lock (messageLock) { clientMessages.Add((IClientMessage)acceptedObject); } } else { throw new Exception("Message of invalid type received in stream."); } } }
private async void ClientReaderUDP() { if (enabled) { //Await an object object recievedObject = await standardizedUDP.ReadObject(); //Check if error if (recievedObject == null) { //Error while reading messages, disconnect Close(true, false); return; } else { //Call new client reader ClientReaderUDP(); } //Parse based on type if (recievedObject is IClientMessage) { //Forward message to other clients if (enabled) { lobby.ForwardToClients(this, (IClientMessage)recievedObject, sendTCP: false); } } if (recievedObject is IServerMessage) { //Run server message if (enabled) { ((IServerMessage)recievedObject).ServerAction(lobby, this); } } } }