Hello,
I converted one of my plugins to C#. It works fine without threading. But with threading it crashes randomly like 1 time per day.
Here is the debug log:
And here is the source code, any idea how to fix that crash?:
I converted one of my plugins to C#. It works fine without threading. But with threading it crashes randomly like 1 time per day.
Here is the debug log:
Code:
========== OUTPUTING STACK TRACE ==================
(0x002533B0) (rust_server): (filename not available): Behaviour::Transfer<StreamedBinaryWrite<0> > + 0x27f90
(0x003A248E) (rust_server): (filename not available): Behaviour::Transfer<StreamedBinaryWrite<0> > + 0x17706e
(0x0FE3F4A8) (Mono JIT code): (filename not available): (wrapper managed-to-native) UnityEngine.Object:FindObjectsOfType (System.Type) + 0x28 (0FE3F480 0FE3F4CC) [03AB4E70 - Unity Root Domain] + 0x0
(0x0FE3EF77) (Mono JIT code): (filename not available): Fougerite.Hooks:HandleuLinkDisconnect (string,object) + 0x57 (0FE3EF20 0FE3F429) [03AB4E70 - Unity Root Domain] + 0x0
(0x0FE3EF09) (Mono JIT code): (filename not available): Class52:method_435 (string,object) + 0x19 (0FE3EEF0 0FE3EF0E) [03AB4E70 - Unity Root Domain] + 0x0
(0x0FE3EBAB) (Mono JIT code): (filename not available): Class52:vmethod_3 (string,object) + 0x3b (0FE3EB70 0FE3EBD5) [03AB4E70 - Unity Root Domain] + 0x0
(0x0FE3EA92) (Mono JIT code): (filename not available): Class45:method_4 (string,object) + 0x42 (0FE3EA50 0FE3EAB8) [03AB4E70 - Unity Root Domain] + 0x0
(0x2880CE4E) (Mono JIT code): (filename not available): Class48:method_269 (string,Class56) + 0x3d6 (2880CA78 2880CE79) [03AB4E70 - Unity Root Domain] + 0x0
(0x12463435) (Mono JIT code): (filename not available): Class48:method_252 (Class56,bool,int) + 0x85 (124633B0 1246345F) [03AB4E70 - Unity Root Domain] + 0x0
(0x12463295) (Mono JIT code): (filename not available): Class48:method_250 (uLink.NetworkPlayer,bool,int) + 0x1ad (124630E8 12463393) [03AB4E70 - Unity Root Domain] + 0x0
(0x124630AF) (Mono JIT code): (filename not available): uLink.Network:CloseConnection (uLink.NetworkPlayer,bool,int) + 0x1f (12463090 124630D5) [03AB4E70 - Unity Root Domain] + 0x0
(0x12463058) (Mono JIT code): (filename not available): NetCull:CloseConnection (uLink.NetworkPlayer,bool) + 0x18 (12463040 1246307E) [03AB4E70 - Unity Root Domain] + 0x0
(0x12463026) (Mono JIT code): (filename not available): NetUser:Kick (NetError,bool) + 0xd6 (12462F50 12463034) [03AB4E70 - Unity Root Domain] + 0x0
(0x12462F4B) (Mono JIT code): (filename not available): Fougerite.Player:Disconnect () + 0x3b (12462F10 12462F50) [03AB4E70 - Unity Root Domain] + 0x0
(0x2877AD16) (Mono JIT code): (filename not available): WhiteListCountry.WhiteListCountry:WLCountry (Fougerite.Player) + 0x31e (2877A9F8 2877AE9C) [03AB4E70 - Unity Root Domain] + 0x0
(0x2877A7D1) (Mono JIT code): (filename not available): WhiteListCountry.WhiteListCountry/<>c__DisplayClass1:<PlayerConnect>b__0 () + 0x19 (2877A7B8 2877A7D6) [03AB4E70 - Unity Root Domain] + 0x0
(0x0407F659) (Mono JIT code): (filename not available): (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr) + 0x41 (0407F618 0407F6AD) [03AB4E70 - Unity Root Domain] + 0x0
(0x100F0376) (mono): (filename not available): mono_set_defaults + 0x22cb
(0x1005D78C) (mono): (filename not available): mono_runtime_invoke + 0x51
(0x1005DBA8) (mono): (filename not available): mono_runtime_delegate_invoke + 0x44
(0x1007DA95) (mono): (filename not available): mono_thread_interruption_request_flag + 0x440
(0x1010B4D6) (mono): (filename not available): mono_unity_thread_clear_domain_fields + 0x3a4b
(0x749F7C04) (KERNEL32): (filename not available): BaseThreadInitThunk + 0x24
(0x76F7AB8F) (ntdll): (filename not available): RtlInitializeExceptionChain + 0x8f
(0x76F7AB5A) (ntdll): (filename not available): RtlInitializeExceptionChain + 0x5a
========== END OF STACKTRACE ===========
C#:
namespace WhiteListCountry
{
using Fougerite;
using Fougerite.Events;
using System;
using System.Globalization;
using System.IO;
using System.Threading;
using System.Collections.Generic;
using UnityEngine;
using GeoIP;
public class WhiteListCountry : Module
{
public static IniParser ConfigINI;
//public static DataStore ds = DataStore.GetInstance();
public static Dictionary<string, string> PluginSettings = new Dictionary<string, string> { };
public void WLCountry(Player pl)
{
try
{
GeoIP geo = GeoIP.Instance;
if (geo.GetDataOfIP(pl.IP) == null)
{
if (PluginSettings["SAM"] == "true")
{
string msg = PluginSettings["JM"];
msg = msg.Replace("%PLAYER%", pl.Name);
msg = msg.Replace("%COUNTRY%", PluginSettings["UL"]);
Server.GetServer().Broadcast(msg);
}
return;
}
string countrycode = geo.GetDataOfIP(pl.IP).CountryShort;
string country = geo.GetDataOfIP(pl.IP).Country;
string whitelist = PluginSettings["WL"];
string wlp = PluginSettings["WLP"];
string steamid = pl.SteamID;
if (find(whitelist, countrycode, wlp, steamid) == false)
{
string playerdisconnectMSG = PluginSettings["PDM"];
if (PluginSettings["SDM"] == "true")
{
string msg = PluginSettings["DM"];
msg = msg.Replace("%PLAYER%", pl.Name);
msg = msg.Replace("%COUNTRY%", country);
Server.GetServer().Broadcast(msg);
}
pl.Message(playerdisconnectMSG + " [" + countrycode + "]");
pl.Disconnect();
}
else
{
if (PluginSettings["SAM"] == "true")
{
string msg = PluginSettings["JM"];
msg = msg.Replace("%PLAYER%", pl.Name);
msg = msg.Replace("%COUNTRY%", country);
Server.GetServer().Broadcast(msg);
}
}
//Logger.Log(pl.Name + " connected to this server");
//Server.GetServer().Broadcast(playername + " has connected from " + country);
}
catch
{
string msg = PluginSettings["JM"];
msg = msg.Replace("%PLAYER%", pl.Name);
msg = msg.Replace("%COUNTRY%", PluginSettings["UL"]);
Server.GetServer().Broadcast(msg);
}
}
public void PlayerConnect(Player pl)
{
Thread thread = new Thread(() =>WLCountry(pl));
thread.Start();
}
public bool find(string whitelist, string CountryCode, string wlp, string steamid)
{
try
{
whitelist = whitelist.Replace(" ", "");
string[] wl = whitelist.Split(',');
wlp = wlp.Replace(" ", "");
string[] wlpl = wlp.Split(',');
// Whitelist search
foreach (string s in wl)
{
if (CountryCode == s)
{
return true;
}
else
{
continue;
}
}
// WhiteListedPlayers search
foreach (string s in wlpl)
{
if (steamid == s)
{
return true;
}
else
{
continue;
}
}
return false;
}
catch
{
return false;
}
}
public void Command(Fougerite.Player Player, string cmd, string[] args)
{
if ((cmd == "wlreload") && Player.Admin)
{
if (args.Length == 0)
{
PluginSettings.Clear();
ConfigINI = new IniParser(@"Save\WhiteListCountry\Config.ini");
PluginSettings.Add("SAM", ConfigINI.GetSetting("Settings", "ShowAcceptedMessage"));
PluginSettings.Add("SDM", ConfigINI.GetSetting("Settings", "ShowDeniedMessage"));
PluginSettings.Add("WL", ConfigINI.GetSetting("WhiteList", "WhiteListedCountries"));
PluginSettings.Add("WLP", ConfigINI.GetSetting("WhiteList", "WhiteListedPlayers"));
PluginSettings.Add("JM", ConfigINI.GetSetting("Messages", "JoinMessage"));
PluginSettings.Add("PDM", ConfigINI.GetSetting("Messages", "PlayerDisconnectMessage"));
PluginSettings.Add("DM", ConfigINI.GetSetting("Messages", "ServerDisconnectMessage"));
PluginSettings.Add("UL", ConfigINI.GetSetting("Messages", "UnknownLocation"));
Player.Message("WhiteListCountry settings reloaded");
}
}
}
public override void DeInitialize()
{
Hooks.OnCommand -= new Hooks.CommandHandlerDelegate(this.Command);
Hooks.OnPlayerConnected -= PlayerConnect;
}
public override void Initialize()
{
Hooks.OnCommand += new Hooks.CommandHandlerDelegate(this.Command);
Hooks.OnPlayerConnected += PlayerConnect;
if (!Directory.Exists(@"Save\WhiteListCountry"))
{
Directory.CreateDirectory(@"Save\WhiteListCountry");
}
if (!File.Exists(@"Save\WhiteListCountry\Config.ini"))
{
File.Create(@"Save\WhiteListCountry\Config.ini").Close();
ConfigINI = new IniParser(@"Save\WhiteListCountry\Config.ini");
ConfigINI.AddSetting("Settings", "ShowAcceptedMessage", "true");
ConfigINI.AddSetting("Settings", "ShowDeniedMessage", "true");
ConfigINI.AddSetting("WhiteList", "WhiteListedCountries", "DE, NL");
ConfigINI.AddSetting("WhiteList", "WhiteListedPlayers", "76561197970657636");
ConfigINI.AddSetting("Messages", "JoinMessage", "%PLAYER% has connected from: %COUNTRY%");
ConfigINI.AddSetting("Messages", "PlayerDisconnectMessage", "Your country is not on the servers whitelist!");
ConfigINI.AddSetting("Messages", "ServerDisconnectMessage", "%PLAYER% is trying to connect from: %COUNTRY%, but it's not whitelisted");
ConfigINI.AddSetting("Messages", "UnknownLocation", "A hidden location");
ConfigINI.Save();
}
ConfigINI = new IniParser(@"Save\WhiteListCountry\Config.ini");
PluginSettings.Clear();
PluginSettings.Add("SAM", ConfigINI.GetSetting("Settings", "ShowAcceptedMessage"));
PluginSettings.Add("SDM", ConfigINI.GetSetting("Settings", "ShowDeniedMessage"));
PluginSettings.Add("WL", ConfigINI.GetSetting("WhiteList", "WhiteListedCountries"));
PluginSettings.Add("WLP", ConfigINI.GetSetting("WhiteList", "WhiteListedPlayers"));
PluginSettings.Add("JM", ConfigINI.GetSetting("Messages", "JoinMessage"));
PluginSettings.Add("PDM", ConfigINI.GetSetting("Messages", "PlayerDisconnectMessage"));
PluginSettings.Add("DM", ConfigINI.GetSetting("Messages", "ServerDisconnectMessage"));
PluginSettings.Add("UL", ConfigINI.GetSetting("Messages", "UnknownLocation"));
}
public override string Author
{
get
{
return "Nordi";
}
}
public override string Description
{
get
{
return "WhiteListCountry";
}
}
public override string Name
{
get
{
return "WhiteListCountry";
}
}
public override System.Version Version
{
get
{
return new System.Version("1.0");
}
}
}
}