Ejemplo n.º 1
0
 /// <summary>
 /// Sends and closes in order to close socket
 /// </summary>
 public void Close()
 {
     if (!(server is null))
     {
         Networking.SendAndClose(server.TheSocket, "");
     }
 }
Ejemplo n.º 2
0
        private void ServeHttpRequest(SocketState state)
        {
            if (state.ErrorOccured)
            {
                return;
            }
            string request = state.GetData();

            state.RemoveData(0, request.Length);
            string response = BuildHtmlResponse(request);

            Networking.SendAndClose(state.TheSocket, response);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This method calls the appropriate methods
        /// to retrieve data from the database and respond to users
        /// </summary>
        /// <param name="state"></param>
        private void ServeHttpRequest(SocketState state)
        {
            if (state.ErrorOccured)
            {
                return;
            }

            string request = state.GetData();

            // serve GET game?player request
            if (request.Contains("games?player="))
            {
                // calculate and get the player's name from the request string
                int    firstIndex  = request.IndexOf("=") + 1;
                int    secondIndex = request.IndexOf("HTTP");
                int    nameLength  = (secondIndex - firstIndex) - 1;
                string name        = request.Substring(firstIndex, nameLength);

                database.GetSpecificGame(name);

                Networking.SendAndClose(state.TheSocket,
                                        WebViews.GetPlayerGames(name, database.gameSessions));
            }

            // serve GET games request
            else if (request.Contains("games"))
            {
                database.GetGames();
                Networking.SendAndClose(state.TheSocket,
                                        WebViews.GetAllGames(database.games));
            }
            // serve the default request which will show the homepage
            else if (request.Contains("GET"))
            {
                Networking.SendAndClose(state.TheSocket,
                                        WebViews.GetHomePage(2));
            }
            else
            {
                Networking.SendAndClose(state.TheSocket,
                                        WebViews.Get404());
            }
        }