public static void RVExtension(StringBuilder output, int outputsize, string input)
 {
     try
     {
         LastUpdateTime = DateTime.Now;
         var CleanInput = input.Replace("\"", string.Empty).Replace("'", string.Empty);
         if (CleanInput.StartsWith("[GetCacheData", StringComparison.OrdinalIgnoreCase))
         {
             var Args = GetNETObjects(CleanInput);
             if (!ReferenceEquals(Args[1], null) && !ReferenceEquals(Args[2], null) && !ReferenceEquals(Args[3], null))
             {
                 PlayerName = (string)Args[1];
                 PlayerPos  = PosToString((List <object>)Args[2]);
                 ServerIP   = (string)Args[3];
                 var NewOutput = new StringBuilder("[[");
                 lock (UnitsLock)
                 {
                     foreach (string FarUnit in FarUnits)
                     {
                         if (!OldFarUnits.Contains(FarUnit))
                         {
                             NewOutput.Append(FarUnit + ",");
                         }
                     }
                 }
                 if (NewOutput.Length > 2)
                 {
                     NewOutput.Remove(NewOutput.Length - 1, 1);
                 }
                 NewOutput.Append("],[");
                 lock (UnitsLock)
                 {
                     foreach (string NearUnit in NearUnits)
                     {
                         if (!OldNearUnits.Contains(NearUnit))
                         {
                             NewOutput.Append(NearUnit + ",");
                         }
                     }
                 }
                 if (!NewOutput.ToString().EndsWith("["))
                 {
                     NewOutput.Remove(NewOutput.Length - 1, 1);
                 }
                 NewOutput.Append("]]");
                 var NewFinalOutput = NewOutput.ToString();
                 while (NewFinalOutput.Contains("[,") || NewFinalOutput.Contains(",]") || NewFinalOutput.Contains(",,"))
                 {
                     NewFinalOutput = NewFinalOutput.Replace("[,", "[").Replace(",]", "]").Replace(",,", ",");
                 }
                 output.Append(NewFinalOutput);
                 lock (UnitsLock)
                 {
                     OldFarUnits  = new HashSet <string>(FarUnits);
                     OldNearUnits = new HashSet <string>(NearUnits);
                 }
             }
         }
         else if (CleanInput.StartsWith("[Reset", StringComparison.OrdinalIgnoreCase))
         {
             var Args = GetNETObjects(CleanInput);
             if (!ReferenceEquals(Args[1], null) && !ReferenceEquals(Args[2], null))
             {
                 ServerIP   = (string)Args[1];
                 UMissionID = (string)Args[2];
                 DateTime EndDate;
                 DateTime.TryParse("30" + "." + "12" + "." + "2017", out EndDate); //<----- Hier Ablaufdatum des Events + 1 Tag eintragen, damit die DLL nur für das vorgesehene Event benutzt werden kann
                 if (EndDate >= DateTime.Now)
                 {
                     if (ReferenceEquals(AlreadyStarted, null) || !AlreadyStarted)
                     {
                         NearUnits      = new HashSet <string>();
                         FarUnits       = new HashSet <string>();
                         OldNearUnits   = new HashSet <string>();
                         OldFarUnits    = new HashSet <string>();
                         UnitsLock      = new object();
                         AlreadyStarted = true;
                         new Thread(() =>
                         {
                             ManageCommunication();
                         }).Start();
                     }
                     else
                     {
                         Environment.Exit(0);
                     }
                 }
                 else
                 {
                     throw new InvalidDateException(EndDate);
                 }
             }
         }
         else if (CleanInput.StartsWith("Test", StringComparison.OrdinalIgnoreCase))
         {
             output.Append("Test");
         }
         output.Append(string.Empty);
     }
     catch (Exception ex)
     {
         output.Append('"' + "HandleClient.dll" + "\r\n" + ex.Message + "\r\n" + ex.StackTrace + '"');
     }
 }
Beispiel #2
0
 public static void RVExtension(StringBuilder output, int outputsize, string input)
 {
     try
     {
         LastUpdateTime = DateTime.Now;
         var CleanInput = input.Replace("\"", string.Empty).Replace("'", string.Empty);
         if (CleanInput.StartsWith("[GetCacheData", StringComparison.OrdinalIgnoreCase))
         {
             var Args = GetNETObjects(CleanInput);
             if (!ReferenceEquals(Args[1], null) && !ReferenceEquals(Args[2], null) && !ReferenceEquals(Args[3], null))
             {
                 PlayerName = (string)Args[1];
                 PlayerPos  = PosToString((List <object>)Args[2]);
                 ServerIP   = (string)Args[3];
                 var NewOutput = new StringBuilder("[[");
                 lock (UnitsLock)
                 {
                     foreach (string FarUnit in FarUnits)
                     {
                         if (!OldFarUnits.Contains(FarUnit))
                         {
                             NewOutput.Append(FarUnit + ",");
                         }
                     }
                 }
                 if (NewOutput.Length > 2)
                 {
                     NewOutput.Remove(NewOutput.Length - 1, 1);
                 }
                 NewOutput.Append("],[");
                 lock (UnitsLock)
                 {
                     foreach (string NearUnit in NearUnits)
                     {
                         if (!OldNearUnits.Contains(NearUnit))
                         {
                             NewOutput.Append(NearUnit + ",");
                         }
                     }
                 }
                 if (!NewOutput.ToString().EndsWith("["))
                 {
                     NewOutput.Remove(NewOutput.Length - 1, 1);
                 }
                 NewOutput.Append("]]");
                 var NewFinalOutput = NewOutput.ToString();
                 while (NewFinalOutput.Contains("[,") || NewFinalOutput.Contains(",]") || NewFinalOutput.Contains(",,"))
                 {
                     NewFinalOutput = NewFinalOutput.Replace("[,", "[").Replace(",]", "]").Replace(",,", ",");
                 }
                 output.Append(NewFinalOutput);
                 lock (UnitsLock)
                 {
                     OldFarUnits  = new HashSet <string>(FarUnits);
                     OldNearUnits = new HashSet <string>(NearUnits);
                 }
             }
         }
         else if (CleanInput.StartsWith("[Reset", StringComparison.OrdinalIgnoreCase))
         {
             var Args = GetNETObjects(CleanInput);
             if (!ReferenceEquals(Args[1], null) && !ReferenceEquals(Args[2], null))
             {
                 ServerIP   = (string)Args[1];
                 UMissionID = (string)Args[2];
                 DateTime EndDate;
                 DateTime.TryParseExact("15" + "." + "2" + "." + "2018", "dd.M.yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out EndDate); //<----- Hier Ablaufdatum des Events + 1 Tag eintragen, damit die DLL nur für das vorgesehene Event benutzt werden kann
                 if (EndDate >= DateTime.Now)
                 {
                     if (ReferenceEquals(AlreadyStarted, null) || !AlreadyStarted)
                     {
                         NearUnits      = new HashSet <string>();
                         FarUnits       = new HashSet <string>();
                         OldNearUnits   = new HashSet <string>();
                         OldFarUnits    = new HashSet <string>();
                         UnitsLock      = new object();
                         AlreadyStarted = true;
                         new Thread(() =>
                         {
                             ManageCommunication();
                         }).Start();
                     }
                     else
                     {
                         Environment.Exit(0);
                     }
                 }
                 else
                 {
                     throw new InvalidDateException(EndDate);
                 }
             }
         }
         else if (CleanInput.StartsWith("[Test", StringComparison.OrdinalIgnoreCase))
         {
             var Args = GetNETObjects(CleanInput);
             if (!ReferenceEquals(Args[1], null) && !ReferenceEquals(Args[2], null))
             {
                 ServerIP   = (string)Args[1];
                 UMissionID = (string)Args[2];
                 DateTime EndDate;
                 DateTime.TryParseExact("15" + "." + "2" + "." + "2018", "dd.M.yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out EndDate); //<----- Hier Ablaufdatum des Events + 1 Tag eintragen, damit die DLL nur für das vorgesehene Event benutzt werden kann
                 if (EndDate >= DateTime.Now)
                 {
                     try
                     {
                         using (var CurClient = new TcpClient(ServerIP, 50100))
                         {
                             using (var CurStream = CurClient.GetStream())
                             {
                                 CurStream.ReadTimeout  = 1250;
                                 CurStream.WriteTimeout = 1250;
                                 var TestData = CompressString(UMissionID + "Test|");
                                 CurStream.Write(TestData, 0, TestData.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.Equals("Test"))
                                         {
                                             output.Append("Test");
                                         }
                                     }
                                     CurStream.Close();
                                 }
                             }
                             CurClient.Close();
                         }
                     } catch { }
                 }
                 else
                 {
                     throw new InvalidDateException(EndDate);
                 }
             }
         }
         output.Append(string.Empty);
     }
     catch (Exception ex)
     {
         output.Append('"' + "HandleClient.dll" + "\r\n" + ex.Message + "\r\n" + ex.StackTrace + '"');
     }
 }