public static Packet RetrievePacket(int packetSize, ref List<byte> buffer) { Packet p = null; JObject json = RetrieveJson(packetSize, ref buffer); if (json == null) return null; //Console.WriteLine("Got " + json["CMD"].ToString().ToUpper() + " packet."); switch (json["CMD"].ToString().ToUpper()) { case LoginResponsePacket.LoginRcmd: p = new LoginResponsePacket(json); break; case ChatPacket.DefCmd: p = new ChatPacket(json); break; case SubscribePacket.DefCmd: p = SubscribePacket.GetSubscribePacket(json); break; case DataFromClientPacket<Object>.DefCmd: //only measurements are supported. p = new DataFromClientPacket<Measurement>(json); break; case PullResponsePacket<Object>.DefCmd: p = HandlePullResponsePacket(json); break; case PushPacket<Object>.DefCmd: p = HandlePushPacket(json); break; case NotifyPacket.Cmd: p = new NotifyPacket(json); break; default: Console.WriteLine("Unsupported packet type: {0}", json["CMD"].ToString()); break; } return p; }
private void HandleLoginPacket(JObject json) { Console.WriteLine(Resources.ClientHandler_Debug_HandleLoginPacket); //Recieve the username and password from json. var username = json["username"].ToString(); var password = json["password"].ToString(); JObject returnJson; //Code to check User/pass here if (Authentication.Authenticate(username, password, this)) { currentUser = _database.getUser(username); returnJson = new LoginResponsePacket( Statuscode.Status.Ok, Authentication.GetUser(username).AuthToken, currentUser ).ToJsonObject(); } 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. Console.WriteLine(returnJson.ToString()); Send(returnJson.ToString()); }