internal static bool ParseResponseHeader(NetIncomingMessage response, out MasterServerMessageType type, out MasterServerMessageResult result) { type = MasterServerMessageType.Undefined; result = MasterServerMessageResult.Undefined; try { type = (MasterServerMessageType)response.ReadByte(); result = (MasterServerMessageResult)response.ReadByte(); } catch { return(false); } if (!Enum.IsDefined(typeof(MasterServerMessageType), type) || !Enum.IsDefined(typeof(MasterServerMessageResult), result) || type == MasterServerMessageType.Undefined || result == MasterServerMessageResult.Undefined) { return(false); } return(true); }
internal static void SendErrorResponse(NetPeer peer, IPEndPoint recipientEndPoint, MasterServerMessageType requestType, MasterServerMessageResult error) { var response = peer.CreateMessage(); response.Write((byte)requestType); response.Write((byte)error); peer.SendUnconnectedMessage(response, recipientEndPoint); }
internal static bool ParseExpectedResponseHeader(NetIncomingMessage response, MasterServerMessageType expectedType) { MasterServerMessageType type; MasterServerMessageResult result; if (ParseResponseHeader(response, out type, out result)) { if (type == expectedType && result == MasterServerMessageResult.Ok) { return(true); } else { Debug.WriteLine("Unexpected response header from master server, expected " + expectedType.ToString() + " and got " + type.ToString() + " with result " + result.ToString()); } } return(false); }