Beispiel #1
0
 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);
 }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
        }