示例#1
0
        static void Main(string[] args)
        {
            AllUser AllPlayer = new AllUser();
            AllPrey AllPrey   = new AllPrey();

            ReceiverUDP.Receiver(localPort, AllPlayer, AllPrey);
        }
示例#2
0
文件: Command.cs 项目: raBpywa/Alice
        private static void _RegistrNewPrey(string[] str_com, IPEndPoint remoteEP, AllPrey AllPrey)
        {
            Prey _prey = new Prey(remoteEP.Address.ToString(), remoteEP.Port, str_com[1], BaseTools._GenerateTokenPrey());

            AllPrey.AllPrey_database.Add(_prey);
            byte[] camm = BaseTools.Convertbtst("[token][" + _prey.Token_sacrifice + "]");
            ReceiverUDP.udpServer.Send(camm, camm.Length, remoteEP);
            Console.WriteLine(remoteEP.Address + ":" + remoteEP.Port + "присвоен токен " + _prey.Token_sacrifice);
            AllPrey.Save(_prey.Name_sacrifice, _prey.Token_sacrifice, remoteEP.Address.ToString(), remoteEP.Port.ToString());
        }
示例#3
0
        public static void Receiver(int localPort, AllUser AllPlayer, AllPrey AllPrey)
        {
            Console.WriteLine("Whait connect\n");
            udpServer = new UdpClient(localPort);
            var outer = Task.Factory.StartNew(() => BaseTools._Cheak_online_Prey(AllPrey));

            while (true)
            {
                var remoteEP = new IPEndPoint(IPAddress.Any, 19999);

                var data = udpServer.Receive(ref remoteEP);
                Console.WriteLine("Подключен " + remoteEP.Address + ":" + remoteEP.Port + " --> " + BaseTools.Convertbtst(data));
                Command._start_command(data, remoteEP, AllPlayer, AllPrey);
            }
        }
示例#4
0
        public static void _Cheak_online_Prey(AllPrey AllPrey)
        {
            while (true)
            {
                for (int i = 0; i < AllPrey.AllPrey_database.Count; i++)
                {
                    if (AllPrey.AllPrey_database[i].timeonline > DateTime.Now.AddSeconds(-25))
                    {
                        AllPrey.AllPrey_database[i].online = true; /*Console.WriteLine(" yes " + AllPrey.AllPrey_database[i].Token_sacrifice +" "+ AllPrey.AllPrey_database[i].timeonline +" "+ DateTime.Now.AddSeconds(25));*/
                    }
                    else
                    {
                        AllPrey.AllPrey_database[i].online = false;
                    }
                }

                Thread.Sleep(3000);
            }
        }
示例#5
0
文件: Command.cs 项目: raBpywa/Alice
        private static void _NeedPrey(string[] str_com, IPEndPoint remoteEP, AllPrey AllPrey)
        {
            Prey cheackPrey = new Prey(str_com[1], str_com[2]);

            foreach (var prey in AllPrey.AllPrey_database)
            {
                if (_ComparePrey(prey, cheackPrey))
                {
                    string cmdforclient = "[for_prey_connect][" + prey.online + "][" + prey.ip + "]";
                    Console.WriteLine(cmdforclient);
                    byte[] bt = BaseTools.Convertbtst(cmdforclient);
                    ReceiverUDP.udpServer.Send(bt, bt.Length, remoteEP);

                    string cmdforsrv = "[for_prey_connect][" + remoteEP + "]";
                    Console.WriteLine(cmdforsrv);
                    byte[] btsrv = BaseTools.Convertbtst(cmdforsrv);
                    ReceiverUDP.udpServer.Send(btsrv, btsrv.Length, prey.ip);
                }
            }
        }
示例#6
0
文件: Command.cs 项目: raBpywa/Alice
        public static void _start_command(byte[] command, IPEndPoint remoteEP, AllUser AllPlayer, AllPrey AllPrey)
        {
            string str_command = BaseTools.Convertbtst(command);

            string[] mas_com = str_command.Split(new char[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries);


            switch (mas_com[0])
            {
            case "ping_1":
                _for_ping(remoteEP);
                break;

            case "0":
                _for_new_user(AllPlayer, remoteEP);
                break;

            case "prey_get_token":
                _RegistrNewPrey(mas_com, remoteEP, AllPrey);
                break;

            case "prey_online":
                _ForPreyOnline(mas_com, remoteEP);
                break;

            case "append_prey":
                _AppendPrey(mas_com, remoteEP, AllPlayer);
                break;

            case "need_prey":
                _NeedPrey(mas_com, remoteEP, AllPrey);
                break;

            default:
                _OtherCommand(AllPlayer, remoteEP, mas_com);
                break;
            }
        }