Added new functionality

This commit is contained in:
2015-10-08 18:29:24 +02:00
parent 33697cfc3e
commit c6735fadc3
5 changed files with 51 additions and 48 deletions
+4 -6
View File
@@ -24,7 +24,6 @@ namespace ErgometerServer
List<Meting> metingen;
List<ChatMessage> chat;
public ClientThread(TcpClient client, Server server)
{
this.client = client;
@@ -66,18 +65,17 @@ namespace ErgometerServer
{
name = input.DisplayName;
loggedin = true;
Console.WriteLine(name + " (client) connected");
Console.WriteLine(name + " (client) connected with password: " + input.Password);
FileHandler.CreateSession(session, name);
}
break;
case NetCommand.CommandType.DATA:
metingen.Add(input.Meting);
server.sendToDoctor(input);
FileHandler.WriteMetingen(session, metingen);
server.SendToDoctor(input);
break;
case NetCommand.CommandType.CHAT:
chat.Add(new ChatMessage(name, input.ChatMessage));
server.sendToDoctor(input);
server.SendToDoctor(input);
Console.WriteLine(name + ": " + input.ChatMessage);
break;
case NetCommand.CommandType.LOGOUT:
@@ -94,7 +92,7 @@ namespace ErgometerServer
}
}
public void writeToClient(NetCommand command)
public void SendToClient(NetCommand command)
{
NetHelper.SendNetCommand(client, command);
if (command.Type == NetCommand.CommandType.CHAT)
-33
View File
@@ -1,33 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
namespace ErgometerServer
{
class DoctorSessionThread
{
public int session { get; }
private TcpClient client;
private DoctorThread doctor;
private Boolean running;
public DoctorSessionThread(int session, TcpClient client, DoctorThread doctor)
{
this.session = session;
this.client = client;
this.doctor = doctor;
}
public void run()
{
running = true;
while (running)
{
}
}
}
}
+1 -1
View File
@@ -42,7 +42,7 @@ namespace ErgometerServer
Console.WriteLine("Doctor logged out");
break;
case NetCommand.CommandType.CHAT:
server.sendToClient(input);
server.SendToClient(input);
Console.WriteLine(input);
break;
default:
+3 -3
View File
@@ -33,8 +33,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="ErgometerLibrary">
<HintPath>..\..\ErgometerLibrary\ErgometerLibrary\bin\Debug\ErgometerLibrary.dll</HintPath>
<Reference Include="ErgometerLibrary, Version=1.0.2.2, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\ErgometerLibrary\ErgometerLibrary\ErgometerLibrary\bin\Debug\ErgometerLibrary.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
@@ -47,7 +48,6 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ClientThread.cs" />
<Compile Include="DoctorSessionThread.cs" />
<Compile Include="DoctorThread.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Server.cs" />
+43 -5
View File
@@ -19,18 +19,22 @@ namespace ErgometerServer
public List<ClientThread> clients { get; }
private DoctorThread doctor;
private static Dictionary<string, string> users;
public Server()
{
FileHandler.CheckDataFolder();
AppDomain.CurrentDomain.ProcessExit += new EventHandler(OnProcessExit);
Console.WriteLine("Checking datafolder " + FileHandler.DataFolder);
FileHandler.CheckStorage();
users = FileHandler.LoadUsers();
clients = new List<ClientThread>();
TcpListener listener = new TcpListener(NetHelper.GetIP("127.0.0.1"), 8888);
listener.Start();
Console.WriteLine("Server started successfully...");
while (true)
{
Console.WriteLine("Waiting for connection with client...");
@@ -73,7 +77,7 @@ namespace ErgometerServer
thread.Start();
}
public void sendToDoctor(NetCommand command)
public void SendToDoctor(NetCommand command)
{
if (doctor != null)
{
@@ -85,15 +89,49 @@ namespace ErgometerServer
}
}
public void sendToClient(NetCommand command)
public void BroadcastToClients(NetCommand command)
{
foreach (ClientThread clientThread in clients)
{
clientThread.SendToClient(command);
}
}
public void SendToClient(NetCommand command)
{
foreach (ClientThread clientThread in clients)
{
if (clientThread.session == command.Session)
{
clientThread.writeToClient(command);
clientThread.SendToClient(command);
}
}
}
private void AddUser(string name, string password)
{
users.Add(name, password);
}
private bool CheckPassword(string name, string password)
{
string pass;
bool isOk = users.TryGetValue(name, out pass);
if (!isOk) return false;
return pass == password;
}
private void ChangePassword(string name, string newpassword)
{
}
private static void OnProcessExit(object sender, EventArgs e)
{
FileHandler.SaveUsers(users);
Console.WriteLine("Closing server");
}
}
}