Send length before data
This commit is contained in:
@@ -15,7 +15,7 @@ namespace ErgometerServer
|
|||||||
TcpClient client;
|
TcpClient client;
|
||||||
Server server;
|
Server server;
|
||||||
|
|
||||||
string name;
|
public string name;
|
||||||
public int session { get; }
|
public int session { get; }
|
||||||
|
|
||||||
bool running;
|
bool running;
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ namespace ErgometerServer
|
|||||||
// - Oude data opsturen (metingen) (not tested yet)
|
// - Oude data opsturen (metingen) (not tested yet)
|
||||||
// - Oude sessies bekijken (lijst met sessies) (not tested yet)
|
// - Oude sessies bekijken (lijst met sessies) (not tested yet)
|
||||||
// - Users opvragen (not tested yet)
|
// - Users opvragen (not tested yet)
|
||||||
// - Gegevens van huidige sessie krijgen (gebruikersnaam enz)
|
// - Gegevens van huidige sessie krijgen (gebruikersnaam enz) (not tested yet)
|
||||||
// - Huidige sessies (not tested yet)
|
// - Huidige sessies (not tested yet)
|
||||||
// -
|
// -
|
||||||
case NetCommand.CommandType.LOGOUT:
|
case NetCommand.CommandType.LOGOUT:
|
||||||
@@ -52,16 +52,21 @@ namespace ErgometerServer
|
|||||||
server.SendToClient(input);
|
server.SendToClient(input);
|
||||||
break;
|
break;
|
||||||
case NetCommand.CommandType.USER:
|
case NetCommand.CommandType.USER:
|
||||||
server.AddUser(input.users);
|
server.AddUser(input.DisplayName, input.Password);
|
||||||
break;
|
break;
|
||||||
case NetCommand.CommandType.REQUEST:
|
case NetCommand.CommandType.REQUEST:
|
||||||
switch (input.Request)
|
switch (input.Request)
|
||||||
{
|
{
|
||||||
case NetCommand.RequestType.USERS:
|
case NetCommand.RequestType.USERS:
|
||||||
sendToDoctor(new NetCommand(FileHandler.LoadUsers(), input.Session));
|
sendToDoctor(new NetCommand(NetCommand.LengthType.USERS, server.users.Count, input.Session));
|
||||||
|
foreach (KeyValuePair<string, string> user in server.users)
|
||||||
|
{
|
||||||
|
sendToDoctor(new NetCommand(user.Key, user.Value, input.Session));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case NetCommand.RequestType.OLDDATA:
|
case NetCommand.RequestType.OLDDATA:
|
||||||
List<Meting> metingen = FileHandler.ReadMetingen(input.Session);
|
List<Meting> metingen = FileHandler.ReadMetingen(input.Session);
|
||||||
|
sendToDoctor(new NetCommand(NetCommand.LengthType.DATA, metingen.Count, input.Session));
|
||||||
foreach (Meting meting in metingen)
|
foreach (Meting meting in metingen)
|
||||||
{
|
{
|
||||||
sendToDoctor(new NetCommand(meting, input.Session));
|
sendToDoctor(new NetCommand(meting, input.Session));
|
||||||
@@ -69,6 +74,7 @@ namespace ErgometerServer
|
|||||||
break;
|
break;
|
||||||
case NetCommand.RequestType.ALLSESSIONS:
|
case NetCommand.RequestType.ALLSESSIONS:
|
||||||
int[] sessions = FileHandler.GetAllSessions();
|
int[] sessions = FileHandler.GetAllSessions();
|
||||||
|
sendToDoctor(new NetCommand(NetCommand.LengthType.SESSIONS, sessions.Length, input.Session));
|
||||||
for (int i = 0; i < sessions.Length; i++)
|
for (int i = 0; i < sessions.Length; i++)
|
||||||
{
|
{
|
||||||
sendToDoctor(new NetCommand(NetCommand.CommandType.SESSION, sessions[i]));
|
sendToDoctor(new NetCommand(NetCommand.CommandType.SESSION, sessions[i]));
|
||||||
@@ -76,13 +82,19 @@ namespace ErgometerServer
|
|||||||
break;
|
break;
|
||||||
case NetCommand.RequestType.CURRENTSESSIONS:
|
case NetCommand.RequestType.CURRENTSESSIONS:
|
||||||
List<int> currentsessions = server.GetRunningSessions();
|
List<int> currentsessions = server.GetRunningSessions();
|
||||||
|
sendToDoctor(new NetCommand(NetCommand.LengthType.CURRENTSESSIONS, currentsessions.Count, input.Session));
|
||||||
foreach (int session in currentsessions)
|
foreach (int session in currentsessions)
|
||||||
{
|
{
|
||||||
sendToDoctor(new NetCommand(NetCommand.CommandType.SESSION, session));
|
sendToDoctor(new NetCommand(NetCommand.CommandType.SESSION, session));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case NetCommand.RequestType.SESSIONDATA:
|
case NetCommand.RequestType.SESSIONDATA:
|
||||||
//sendToDoctor(new NetCommand());
|
List<Tuple<int, string>> currentsessionsdata = server.GetRunningSessionsData();
|
||||||
|
sendToDoctor(new NetCommand(NetCommand.LengthType.SESSIONDATA, currentsessionsdata.Count, input.Session));
|
||||||
|
foreach (Tuple<int, string> ses in currentsessionsdata)
|
||||||
|
{
|
||||||
|
sendToDoctor(new NetCommand(ses.Item2, false, ses.Item1));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new FormatException("Unknown Command");
|
throw new FormatException("Unknown Command");
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="ErgometerLibrary, Version=1.0.2.6, Culture=neutral, processorArchitecture=MSIL">
|
<Reference Include="ErgometerLibrary, Version=1.0.2.8, Culture=neutral, processorArchitecture=MSIL">
|
||||||
<SpecificVersion>False</SpecificVersion>
|
<SpecificVersion>False</SpecificVersion>
|
||||||
<HintPath>..\..\..\ErgometerLibrary\ErgometerLibrary\ErgometerLibrary\bin\Debug\ErgometerLibrary.dll</HintPath>
|
<HintPath>..\..\..\ErgometerLibrary\ErgometerLibrary\ErgometerLibrary\bin\Debug\ErgometerLibrary.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace ErgometerServer
|
|||||||
|
|
||||||
public List<ClientThread> clients { get; }
|
public List<ClientThread> clients { get; }
|
||||||
private DoctorThread doctor;
|
private DoctorThread doctor;
|
||||||
private static Dictionary<string, string> users;
|
public Dictionary<string, string> users;
|
||||||
|
|
||||||
public Server()
|
public Server()
|
||||||
{
|
{
|
||||||
@@ -28,6 +28,7 @@ namespace ErgometerServer
|
|||||||
FileHandler.CheckStorage();
|
FileHandler.CheckStorage();
|
||||||
|
|
||||||
users = FileHandler.LoadUsers();
|
users = FileHandler.LoadUsers();
|
||||||
|
|
||||||
clients = new List<ClientThread>();
|
clients = new List<ClientThread>();
|
||||||
|
|
||||||
TcpListener listener = new TcpListener(NetHelper.GetIP("127.0.0.1"), 8888);
|
TcpListener listener = new TcpListener(NetHelper.GetIP("127.0.0.1"), 8888);
|
||||||
@@ -108,7 +109,7 @@ namespace ErgometerServer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddUser(string name, string password)
|
public void AddUser(string name, string password)
|
||||||
{
|
{
|
||||||
users.Add(name, password);
|
users.Add(name, password);
|
||||||
FileHandler.SaveUsers(users);
|
FileHandler.SaveUsers(users);
|
||||||
@@ -144,7 +145,17 @@ namespace ErgometerServer
|
|||||||
sessions.Add(thread.session);
|
sessions.Add(thread.session);
|
||||||
}
|
}
|
||||||
return sessions;
|
return sessions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Tuple<int, string>> GetRunningSessionsData()
|
||||||
|
{
|
||||||
|
List<Tuple<int, string>> sessions = new List<Tuple<int, string>>();
|
||||||
|
foreach (ClientThread thread in clients)
|
||||||
|
{
|
||||||
|
sessions.Add(new Tuple<int, string>(thread.session, thread.name));
|
||||||
|
}
|
||||||
|
return sessions;
|
||||||
|
}
|
||||||
|
|
||||||
private string GeneratePassword(int len = 8)
|
private string GeneratePassword(int len = 8)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user