private void ManageState(string messageReceived) { if (serverState == loopState.MAINSERVER) { if (messageReceived.StartsWith("UPLOAD")) { serverState = loopState.UPLOAD; stateFunction = uploader.ProcessString; Console.WriteLine("Server is now in: " + serverState.ToString() + " state"); } else if (messageReceived.StartsWith("DOWNLOAD")) { serverState = loopState.DOWNLOAD; stateFunction = downloader.processString; Console.WriteLine("Server is now in: " + serverState.ToString() + " state"); } else if (messageReceived.StartsWith("AUTHENTICATE")) { serverState = loopState.AUTHENTICATE; stateFunction = authenticate.ProcessString; Console.WriteLine("Server is now in: " + serverState.ToString() + " state"); } else { stateFunction = mainServer.processString; Console.WriteLine("Server is now in: " + serverState.ToString() + " state"); } } }
public ConnManager(int port, bool tryRandom) { connections = new List <Connection>(); this.port = port; serverState = loopState.MAINSERVER; downloader = new Downloader(); uploader = new Uploader(); mainServer = new MainServer(); authenticate = new Authenticate(); }
public int ProcessServer(Connection conn) { if (conn._state.HasRead()) // unencrypted buffer { string message = conn._state.DequeueRead(); message = StripServerName(message); ProcessCommands(message); // prints out a clients guid and message to console Console.ForegroundColor = conn._state.cc; Console.WriteLine(conn.g.ToString() + " " + message); Console.ResetColor(); // Change state if required ManageState(message); // Process unencrypted message to send List <string> temp = stateFunction(message); if (temp != null) { foreach (string s in temp) { conn._state.EnqueueWrite(s); } } else { serverState = loopState.MAINSERVER; } } else if (conn._state.HasEncRead()) // encrypted buffer { string message = conn._state.EncDequeueRead(sharedKey); message = StripServerName(message); ProcessCommands(message); Console.ForegroundColor = conn._state.cc; Console.WriteLine(conn.g.ToString() + " " + message); Console.ResetColor(); ManageState(message); List <string> temp = stateFunction(message); if (temp != null) { foreach (string s in temp) { conn._state.EncEnqueueWrite(sharedKey, s); } } else { serverState = loopState.MAINSERVER; } } else { Thread.Sleep(1); } return(1); }