示例#1
0
 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();
     }
 }
示例#2
0
        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);
                }
            }
        }
示例#3
0
 public static void Register()
 {
     InterNodeNetwork.RegisterPacketHandler(typeof(PingPacket), HandlePing);
     InterNodeNetwork.RegisterPacketHandler(typeof(ShutdownPacket), HandleShutdown);
 }
示例#4
0
 public static void HandlePing(StarNetPacket _packet, IPEndPoint source, InterNodeNetwork network)
 {
     // Do nothing, this is handled at a lower level
 }
示例#5
0
        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);
                }
            }
        }
示例#6
0
 public static void Register()
 {
     InterNodeNetwork.RegisterPacketHandler(typeof(AddNewUserPacket), HandleAddNewUser);
     InterNodeNetwork.RegisterPacketHandler(typeof(DropUserPacket), HandleDropUser);
 }