This commit is contained in:
2015-10-20 11:18:44 +02:00
parent d5bb2d555d
commit 50c2ceeb56
4 changed files with 18 additions and 16 deletions
+3 -1
View File
@@ -116,7 +116,9 @@ namespace ErgometerServer
client.Close();
break;
default:
throw new FormatException("Unknown command");
if(loggedin)
throw new FormatException("Unknown command");
break;
}
}
+4 -9
View File
@@ -15,7 +15,6 @@ namespace ErgometerServer
bool running;
public DoctorThread(TcpClient client, Server server)
{
this.client = client;
@@ -33,13 +32,6 @@ namespace ErgometerServer
switch (input.Type)
{
//Nog toe te voegen:
// - Oude data opsturen (metingen) (not tested yet)
// - Oude sessies bekijken (lijst met sessies) (not tested yet)
// - Users opvragen (not tested yet)
// - Gegevens van huidige sessie krijgen (gebruikersnaam enz) (not tested yet)
// - Huidige sessies (not tested yet)
// -
case NetCommand.CommandType.LOGOUT:
running = false;
client.Close();
@@ -61,14 +53,15 @@ namespace ErgometerServer
sendToDoctor(new NetCommand(NetCommand.LengthType.USERS, server.users.Count, input.Session));
foreach (KeyValuePair<string, string> user in server.users)
{
Thread.Sleep(10);
sendToDoctor(new NetCommand(user.Key, user.Value, input.Session));
}
break;
case NetCommand.RequestType.OLDDATA:
List<Meting> metingen = FileHandler.ReadMetingen(input.Session);
sendToDoctor(new NetCommand(NetCommand.LengthType.DATA, metingen.Count, input.Session));
foreach (Meting meting in metingen)
{
Thread.Sleep(10);
sendToDoctor(new NetCommand(meting, input.Session));
Console.WriteLine(new NetCommand(meting, input.Session));
}
@@ -78,6 +71,7 @@ namespace ErgometerServer
sendToDoctor(new NetCommand(NetCommand.LengthType.SESSIONS, sessions.Length, input.Session));
for (int i = 0; i < sessions.Length; i++)
{
Thread.Sleep(10);
sendToDoctor(new NetCommand(NetCommand.CommandType.SESSION, sessions[i]));
}
break;
@@ -86,6 +80,7 @@ namespace ErgometerServer
sendToDoctor(new NetCommand(NetCommand.LengthType.SESSIONDATA, currentsessionsdata.Count, input.Session));
foreach (Tuple<int, string> ses in currentsessionsdata)
{
Thread.Sleep(10);
sendToDoctor(new NetCommand(ses.Item2, false, ses.Item1));
}
break;
+9 -6
View File
@@ -95,14 +95,17 @@ namespace ErgometerServer
public static void WriteChat(int session, List<ChatMessage> chat)
{
string write = "";
foreach (ChatMessage c in chat)
if (Directory.Exists(GetSessionFolder(session)))
{
write += c.ToString() + "\n";
}
string write = "";
foreach (ChatMessage c in chat)
{
write += c.ToString() + "\n";
}
File.WriteAllText(GetSessionChat(session), write);
Console.WriteLine("Writing chat: " + GetSessionChat(session));
File.WriteAllText(GetSessionChat(session), write);
Console.WriteLine("Writing chat: " + GetSessionChat(session));
}
}
private static string GetSessionFolder(int session)
+2
View File
@@ -31,6 +31,7 @@ namespace ErgometerServer
clients = new List<ClientThread>();
TcpListener listener = new TcpListener(NetHelper.GetIP("127.0.0.1"), 8888);
//TcpListener listener = new TcpListener(NetHelper.GetIP(GetIp()), 8888);
listener.Start();
Console.WriteLine("Server started successfully...");
@@ -67,6 +68,7 @@ namespace ErgometerServer
localIP = ip.ToString();
}
}
Console.WriteLine(localIP);
return localIP;
}