/// <summary> /// Processes a request, sending data to sender if necessary. /// </summary> /// <param name="packet"></param> private void ProcessRequest(RequestPacket packet) { Model.LogMessages.Add("Request Packet recieved: " + packet.RequestType); switch (packet.RequestType) { case PacketRequestTypeEnum.CharacterSelection: ProcessCharacterSelectionRequest(packet); break; case PacketRequestTypeEnum.CharacterCreation: ProcessCharacterCreationInitializationRequest(packet); break; default: break; } }
/// <summary> /// Returns packet to sender containing the server's announcement, name and the sender's character information. /// </summary> private void ProcessCharacterSelectionRequest(RequestPacket packet) { List<PlayerCharacter> characterList = new List<PlayerCharacter>(); if (Model.ConnectionUsernamesDictionary.ContainsKey(packet.SenderConnection)) { string username = Model.ConnectionUsernamesDictionary[packet.SenderConnection]; using (PlayerCharacterFileAccess repo = new PlayerCharacterFileAccess()) { characterList = repo.GetCharactersByUsername(username); } CharacterSelectionPacket responsePacket = new CharacterSelectionPacket { ServerAnnouncement = Model.ServerAnnouncement, ServerName = Model.ServerName, CharacterList = characterList, CanDeleteCharacters = Model.IsCharacterDeletionEnabled }; Agent.SendPacket(responsePacket, packet.SenderConnection, NetDeliveryMethod.ReliableUnordered); } }
/// <summary> /// Sends a request packet to the currently connected server. /// </summary> /// <param name="requestType"></param> /// <param name="deliveryMethod"></param> public void SendRequest(PacketRequestTypeEnum requestType, NetDeliveryMethod deliveryMethod = NetDeliveryMethod.ReliableUnordered) { RequestPacket packet = new RequestPacket(requestType); Agent.SendPacket(packet, ServerConnection, deliveryMethod); }
private void ProcessRequest(RequestPacket packet) { switch (packet.RequestType) { case PacketRequestTypeEnum.Username: ProcessUsernameRequest(); break; default: break; } }
private void Agent_OnConnectionEstablished(object sender, ConnectionStatusEventArgs e) { Model.LogMessages.Add("Connection requested: " + e.Connection.RemoteEndPoint.Address + ":" + e.Connection.RemoteEndPoint.Port); // Send a request for the user's username. RequestPacket packet = new RequestPacket(PacketRequestTypeEnum.Username); Agent.SendPacket(packet, e.Connection, NetDeliveryMethod.ReliableUnordered); }