public static Packet GetPacketFromJson(JObject json) { if (json == null) return null; Packet p = null; switch ((string)json.GetValue("CMD", StringComparison.CurrentCultureIgnoreCase)) { //case ChatPacket.DefCmd: // p = new ChatPacket(json); // break; case DisconnectPacket.DefCmd: p = new DisconnectPacket(json); break; case LoginPacket.DefCmd: p = new LoginPacket(json); break; case LoginResponsePacket.DefCmd: p = new LoginResponsePacket(json); break; case SerialDataPushPacket.DefCmd: p = new SerialDataPushPacket(json); break; //case RegisterPacket.DefCmd: // p = new RegisterPacket(json); // break; //case RegisterResponsePacket.DefCmd: // p = new RegisterResponsePacket(json); // break; case UserChangedPacket.DefCmd: p = new UserChangedPacket(json); break; case PullResponsePacket.DefCmd: p = new PullResponsePacket<User>(json); break; default: try { p = new ResponsePacket(json); } catch (ArgumentException) { } break; } return p; }
private void OnLoginResultEvent(LoginResponsePacket packet) { ResultDelegate handler = LoginResultEvent; if (handler != null) handler(packet); }
private void HandleLoginPacket(JObject json) { Console.WriteLine("Login packet received"); //Recieve the username and password from json. var packet = new LoginPacket(json); JObject returnJson; //Code to check User/pass here if (Authentication.Authenticate(packet.Username, packet.Passhash, this)) { returnJson = new LoginResponsePacket( Statuscode.Status.Ok, packet.Username, Authentication.GetUser(packet.Username).IsDoctor ); var user = _datastorage.GetUser(packet.Username); if (user != null) { user.OnlineStatus = true; if (!user.IsDoctor) SendToAllOnlineDoctors(new UserChangedPacket(user)); } } else if (Authentication.GetUser(packet.Username) != null) { if (Authentication.GetUser(packet.Username).OnlineStatus) returnJson = new ResponsePacket(Statuscode.Status.AlreadyOnline, "RESP-LOGIN"); else returnJson = new ResponsePacket(Statuscode.Status.SyntaxError, "RESP-LOGIN"); } else //If the code reaches this point, the authentification has failed. { returnJson = new ResponsePacket(Statuscode.Status.InvalidUsernameOrPassword, "RESP-LOGIN"); } //Send the result back to the client. Send(returnJson.ToString()); #if DEBUG Console.WriteLine(packet.ToString()); Console.WriteLine(returnJson.ToString()); #endif }