public SessionTokenResponse Put([FromBody] ClientSessionRequest request) { SessionTokenResponse response = new SessionTokenResponse(); try { if (request != null) { if (!String.IsNullOrEmpty(request.username) && !String.IsNullOrEmpty(request.password)) { DB db = new DB(); response = db.GetSessionToken(request); } else { response.message = new Message("0014", "Ocurrio un error. Todos los datos son requeridos", null); } } else { response.message = new Message("0013", "Ocurrio un error. El body de la peticion es requerido", null); } } catch (Exception ex) { response.message = new Message("0012", "Ocurrio un error.", ex); } return(response); }
public SessionTokenResponse GetSessionToken(ClientSessionRequest sessionRequest) { SessionTokenResponse response = new SessionTokenResponse(); var answer = "0"; try { Open(); command = new SqlCommand("dbo.getUserSessionId", connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@username", sessionRequest.username); command.Parameters.AddWithValue("@password", sessionRequest.password); reader = command.ExecuteReader(); while (reader.Read()) { answer = reader.GetFieldValue <string>(0); } Close(); if (answer != "0") { response.token = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(answer.ToString())); response.message = new Message("0000", "Transaccion exitosa", null); } else { response.message = new Message("0016", "Transaccion fallida", null); } } catch (Exception ex) { response.message = new Message("0015", "Transaccion fallida.", ex); } return(response); }
private void HandleSessionRequest() { TCPPacketConnection tcpConnection; try { ReceivedEvent = new EventWaitHandle(false, EventResetMode.ManualReset); ClientSessionRequest sessionRequest = new ClientSessionRequest(); sessionRequest.Reconnect = ConnectParameters.Reconnect; sessionRequest.ReconnectSessionID = ConnectParameters.SessionID; tcpConnection = new TCPPacketConnection(AcceptedSocket); tcpConnection.Logger = Logger; tcpConnection.DataReceivedEvent += ReadIDResponse; tcpConnection.Send(Adapter.CreateNetworkDataFromPackage(sessionRequest)); tcpConnection.InitializeReceiving(); if (ReceivedEvent.WaitOne(5000) && !Error) { Connection = new NetworkConnection(tcpConnection); Connection.ClientSession = new Session(SessionID); Connected = true; return; } tcpConnection.Disconnect(); } catch { } ErrorMessage = "Server timeout while receiving session ID!"; }
private void HandleSessionRequest(NetworkConnection connection, PackageInterface request) { ClientSessionRequest packet = (ClientSessionRequest)request; if (packet.Reconnect) { ReconnectClientWithPreviousSession(connection, packet); } else { ConnectClientWithNewSession(connection); } }
public ScenarioProvider() { List <PackageInterface> ConnectOnly = new List <PackageInterface>(); Scenarios.Add(ConnectOnly); List <PackageInterface> SessionRequest = new List <PackageInterface>(); ClientSessionRequest sessionRequest = new ClientSessionRequest(); sessionRequest.Reconnect = false; sessionRequest.ReconnectSessionID = 0; SessionRequest.Add(sessionRequest); Scenarios.Add(SessionRequest); List <PackageInterface> ReconnectWithPreviousSession = new List <PackageInterface>(); ReconnectWithPreviousSession.Add(sessionRequest); Scenarios.Add(ReconnectWithPreviousSession); }
private void ReconnectClientWithPreviousSession(NetworkConnection networkConnection, ClientSessionRequest packet) { Logger.RegistrationLog("Client (" + networkConnection.RemoteEndPoint.ToString() + ") want's to reconnect with Session ID " + packet.ReconnectSessionID.ToString()); networkConnection.ClientSession = new Session(packet.ReconnectSessionID); AcceptedConnections.Remove(networkConnection); if (RejoinCallback(networkConnection)) { Logger.RegistrationLog("According to callback client could rejoin the game. Therefore Removing it from Accepted Connections List"); AcceptedConnections.Remove(networkConnection); } else { Logger.RegistrationLog("According to callback client could NOT rejoin the game. "); Logger.RegistrationLog("Removing it from Accepted Connections List and adding it to Conections Ready for Matchmaking."); AcceptedConnections.Remove(networkConnection); Logger.RegistrationLog("Sending Normal Session Response. And assigning him a new Session ID"); networkConnection.ClientSession = new Session(SessionIDGenerator.GetID()); SendSessionResponse(networkConnection); ConnectionsReadyForQueingUpToMatchmaking.Add(networkConnection); } }