Cleaned up ServerConsole
This commit is contained in:
@@ -43,6 +43,7 @@ namespace ErgometerServer
|
||||
running = true;
|
||||
|
||||
session = FileHandler.GenerateSession();
|
||||
Console.WriteLine("Generated new session: " + session);
|
||||
NetHelper.SendNetCommand(client, new NetCommand(session));
|
||||
|
||||
while (running)
|
||||
@@ -52,17 +53,20 @@ namespace ErgometerServer
|
||||
switch(input.Type)
|
||||
{
|
||||
case NetCommand.CommandType.SESSION:
|
||||
|
||||
break;
|
||||
case NetCommand.CommandType.LOGIN:
|
||||
if(input.IsDoctor)
|
||||
{
|
||||
server.ChangeClientToDoctor(client, this);
|
||||
Console.WriteLine("Doctor connected");
|
||||
running = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
name = input.DisplayName;
|
||||
loggedin = true;
|
||||
Console.WriteLine(name + " (client) connected");
|
||||
FileHandler.CreateSession(session, name);
|
||||
}
|
||||
break;
|
||||
@@ -72,10 +76,12 @@ namespace ErgometerServer
|
||||
break;
|
||||
case NetCommand.CommandType.CHAT:
|
||||
chat.Add(new ChatMessage(name, input.ChatMessage));
|
||||
Console.WriteLine(name + ": " + input.ChatMessage);
|
||||
break;
|
||||
case NetCommand.CommandType.LOGOUT:
|
||||
loggedin = false;
|
||||
running = false;
|
||||
Console.WriteLine(name + " logged out");
|
||||
FileHandler.WriteMetingen(session, metingen);
|
||||
FileHandler.WriteChat(session, chat);
|
||||
client.Close();
|
||||
|
||||
@@ -72,62 +72,5 @@ namespace ErgometerServer
|
||||
Thread thread = new Thread(new ThreadStart(doctor.run));
|
||||
thread.Start();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//OLD DO NOT USE
|
||||
static void OldThread(object obj)
|
||||
{
|
||||
TcpClient client = obj as TcpClient;
|
||||
StreamReader reader = new StreamReader(client.GetStream(), Encoding.Unicode);
|
||||
StreamWriter stream = new StreamWriter(client.GetStream(), Encoding.Unicode);
|
||||
string name = null;
|
||||
int session = 0;
|
||||
bool doctor = false;
|
||||
string b = reader.ReadLine();
|
||||
ArrayList data = new ArrayList();
|
||||
while (!b.StartsWith("4»") && !b.EndsWith("logout"))
|
||||
{
|
||||
if (b.StartsWith("5»"))
|
||||
{
|
||||
session = FileHandler.GenerateSession();
|
||||
NetCommand sescommand = new NetCommand(NetCommand.CommandType.SESSION, session);
|
||||
Console.WriteLine(b);
|
||||
Console.WriteLine(sescommand.ToString());
|
||||
stream.WriteLine(sescommand.ToString());
|
||||
stream.Flush();
|
||||
}
|
||||
if(b.StartsWith("1»"))
|
||||
{
|
||||
NetCommand clientCommand = NetCommand.Parse(b);
|
||||
doctor = clientCommand.IsDoctor;
|
||||
name = clientCommand.DisplayName;
|
||||
if (doctor)
|
||||
{
|
||||
//check password
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("login of " + name + " succesful");
|
||||
stream.WriteLine("login succes"); //moet nog geïmplementeerd worden
|
||||
}
|
||||
stream.Flush();
|
||||
}
|
||||
if (b.StartsWith("2»"))
|
||||
{
|
||||
Console.WriteLine(b);
|
||||
data.Add(NetCommand.Parse(b));
|
||||
stream.WriteLine("2»ses" + session + "»succes");
|
||||
}
|
||||
// chat has still to be implemented
|
||||
b = reader.ReadLine();
|
||||
}
|
||||
Console.WriteLine("Closing session: ses" + session);
|
||||
stream.WriteLine("4»" + session + "»logoutsucces");
|
||||
stream.Flush();
|
||||
stream.Close();
|
||||
reader.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user