Пример #1
0
    public override void Left(Triggered o, Trigger t)
    {
        Unit other = o.GetComponent <Unit>();

        if (other != null)
        {
            if (t.GetType() == typeof(NearUnit))
            {
                if (NearUnits.Contains(other))
                {
                    NearUnits.Remove(other);
                }
            }
            if (t.GetType() == typeof(RangeUnit))
            {
                if (RangeUnits.Contains(other))
                {
                    RangeUnits.Remove(other);
                }
            }
        }
    }
Пример #2
0
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        private static bool ManageCommunication()
        {
            while (DateTime.Now < LastUpdateTime.AddSeconds(300))
            {
                try
                {
                    if (!ReferenceEquals(PlayerPos, null))
                    {
                        using (var CurClient = new TcpClient(ServerIP, 50100))
                        {
                            using (var CurStream = CurClient.GetStream())
                            {
                                CurStream.ReadTimeout  = 1250;
                                CurStream.WriteTimeout = 1250;
                                var PlayerData = CompressString(UMissionID + "Post&GetPlayerData|" + PlayerName + "|" + PlayerPos);
                                CurStream.Write(PlayerData, 0, PlayerData.Length);
                                int ReadedByteCount = 0, i = 0;
                                using (var ByteStream = new MemoryStream())
                                {
                                    var buffer = new byte[CurClient.ReceiveBufferSize];
                                    while (((ReadedByteCount == CurClient.ReceiveBufferSize) || (i == 0)) && (i < 35))
                                    {
                                        ReadedByteCount = CurStream.Read(buffer, 0, CurClient.ReceiveBufferSize);
                                        ByteStream.Write(buffer, 0, ReadedByteCount);
                                        i++;
                                    }
                                    if (i != 35)
                                    {
                                        var Message = DecompressString(ByteStream.ToArray());
                                        if (Message.Contains("|"))
                                        {
                                            var Parameter    = Message.Split('|');
                                            var NewFarUnits  = Parameter[0].Split(';');
                                            var NewNearUnits = Parameter[1].Split(';');
                                            lock (UnitsLock)
                                            {
                                                for (int i2 = 0; i2 < NewNearUnits.Length; i2++)
                                                {
                                                    FarUnits.Remove(NewNearUnits[i2]);
                                                    NearUnits.Add(NewNearUnits[i2]);
                                                }
                                                for (int i2 = 0; i2 < NewFarUnits.Length; i2++)
                                                {
                                                    NearUnits.Remove(NewFarUnits[i2]);
                                                    FarUnits.Add(NewFarUnits[i2]);
                                                }
                                            }
                                        }
                                    }
                                    CurStream.Close();
                                }
                            }
                            CurClient.Close();
                        }
                    }
                }
                catch (Exception ex)
                {
                    WriteErrorLog(ex.Message + Environment.NewLine + ex.StackTrace);
                }
                Thread.Sleep(2800);
            }
            Environment.Exit(0);
            return(true);
        }