예제 #1
0
            public static string Explain(ServerRegistrationResponse response)
            {
                switch (response)
                {
                case ServerRegistrationResponse.Valid:
                    return("The server can be registered.");

                case ServerRegistrationResponse.InvalidIP:
                    return("The provided external IP is not corresponding.");

                case ServerRegistrationResponse.InvalidCode:
                    return("The provided security code is not corresponding.");

                case ServerRegistrationResponse.WorldsFull:
                    return("Cannot register a new Server as all the Worlds spots are occupied.");

                default:
                    return(null);
                }
            }
예제 #2
0
        /// <summary>
        /// Initializes the API manager,
        /// passing the given token to the server for confirmation.
        /// </summary>
        public ApiManager(string token, string callsign)
        {
            client = new RestClient(SERVER_ADDRESS);
            RestRequest registerRequest
                = new RestRequest(REGISTRATION_ENDPOINT, Method.GET);

            client.UserAgent = CLIENT_VERSION;

            registerRequest.AddParameter("token", token);
            registerRequest.AddParameter("callsign", callsign);

            registerRequest.OnBeforeDeserialization = resp => { resp.ContentType = "application/json"; };

            var response = client.Execute <ServerRegistrationResponse>(registerRequest);

            if (response.IsSuccessful)
            {
                var deserializer = new JsonDeserializer();
                ServerRegistrationResponse returnPayload = deserializer.Deserialize <ServerRegistrationResponse>(response);

                this.Callsign    = returnPayload.Callsign;
                this.DiscordId   = returnPayload.DiscordId;
                this.DiscordName = returnPayload.DiscordName;
                this.Token       = returnPayload.Token;

                if (this.DiscordId == 0)
                {
                    this.IsRegistered = false;
                }
                else
                {
                    this.IsRegistered = true;
                }
            }
            else
            {
                // do nothing
            }
        }
		private void OnRegistrationResponse(InPacket inPacket)
		{
			ServerRegistrationResponse response = (ServerRegistrationResponse)inPacket.ReadByte();

			switch (response)
			{
				case ServerRegistrationResponse.Valid:
					{
						GameServer.WorldID = inPacket.ReadByte();
						GameServer.ChannelID = inPacket.ReadByte();

						GameServer.ScrollingHeader = inPacket.ReadString();
						GameServer.Rates = new Rates()
						{
							Experience = inPacket.ReadInt(),
							QuestExperience = inPacket.ReadInt(),
							PartyQuestExperience = inPacket.ReadInt(),

							Meso = inPacket.ReadInt(),
							Loot = inPacket.ReadInt(),
						};

						Log.Success("Registered Game as {0}-{1} at {2}.", WorldNameResolver.GetName(GameServer.WorldID),
							GameServer.ChannelID, GameServer.RemoteEndPoint);
						Log.Inform("Rates: {0}x / {1}x / {2}x / {3}x / {4}x.",
							GameServer.Rates.Experience,
							GameServer.Rates.QuestExperience,
							GameServer.Rates.PartyQuestExperience,
							GameServer.Rates.Meso,
							GameServer.Rates.Loot);
					}
					break;

				default:
					throw new NetworkException(RegistrationResponseResolver.Explain(response));
			}
		}