public static void HandleShutdown(StarNetPacket _packet, IPEndPoint source, InterNodeNetwork network) { if (source.Address.Equals(IPAddress.Loopback)) { Console.WriteLine("Shutting down node at request of {0}.", source); network.LocalNode.Shutdown(); } }
public static void HandleDropUser(StarNetPacket _packet, IPEndPoint source, InterNodeNetwork network) { var packet = (DropUserPacket)_packet; if (source.Address.Equals(IPAddress.Loopback)) { using (var session = network.LocalNode.Database.SessionFactory.OpenSession()) { var user = session.Query <User>().SingleOrDefault(u => u.AccountName == packet.AccountName); if (user == null) { Console.WriteLine("Warning: Attempted to drop account that does not exist."); return; } using (var transaction = session.BeginTransaction()) { session.Delete(user); transaction.Commit(); } Console.WriteLine("Dropped user {0} at request of {1}", packet.AccountName, source); } } }
public static void Register() { InterNodeNetwork.RegisterPacketHandler(typeof(PingPacket), HandlePing); InterNodeNetwork.RegisterPacketHandler(typeof(ShutdownPacket), HandleShutdown); }
public static void HandlePing(StarNetPacket _packet, IPEndPoint source, InterNodeNetwork network) { // Do nothing, this is handled at a lower level }
public static void HandleAddNewUser(StarNetPacket _packet, IPEndPoint source, InterNodeNetwork network) { var packet = (AddNewUserPacket)_packet; if (source.Address.Equals(IPAddress.Loopback)) { using (var session = network.LocalNode.Database.SessionFactory.OpenSession()) { if (session.Query <User>().Any(u => u.AccountName == packet.AccountName)) { Console.WriteLine("Warning: Attempted to add account that already exists."); return; } using (var transaction = session.BeginTransaction()) { var user = new User { AccountName = packet.AccountName, Password = packet.Password, NetworkAdmin = packet.NetworkAdmin }; session.SaveOrUpdate(user); transaction.Commit(); } Console.WriteLine("Added user {0} at request of {1}", packet.AccountName, source); } } }
public static void Register() { InterNodeNetwork.RegisterPacketHandler(typeof(AddNewUserPacket), HandleAddNewUser); InterNodeNetwork.RegisterPacketHandler(typeof(DropUserPacket), HandleDropUser); }