InSim.Send_MTC_MessageToConnection("^3You clicked " + BTC.ClickID, Connections[GetConnIdx(BTC.UCID)].UniqueID, 0);
private bool GetUserAdmin(string Username)
{
StreamReader CurrentFile = new StreamReader(SaveDataFolder + "/admins.ini");
string line = null;
while ((line = CurrentFile.ReadLine()) != null)
{
if (line.Trim() == Username)
{
CurrentFile.Close();
return true;
}
}
CurrentFile.Close();
return false;
}
private void OnConnectionJoin(InSim insim, IS_NCN NCN)
{
try
{
_connections.Add(NCN.UCID, new Connections
{
UCID = NCN.UCID,
UName = NCN.UName,
PName = NCN.PName,
IsAdmin = NCN.Admin,
IsCustomAdmin = GetUserAdmin(NCN.UName)
});
}
catch (Exception EX) {}
}
private bool IsConnectionAdmin(Connections CurrentConnection)
{
if (CurrentConnection.IsAdmin == true || CurrentConnection.IsCustomAdmin == true) return true;
return false;
}
else if (command[0] == "!makeadmin")
{
if (!IsConnectionAdmin(_connections[MSO.UCID]))
{
MessageToUCID(MSO.UCID, "You are not an admin");
return;
}
if (command.Length == 1)
{
MessageToUCID(MSO.UCID, "Invalid Format. ^7!makeadmin [username]");
return;
}
bool UsernameFound = false;
string Username = Text.Remove(0, command[0].Length + 1);
foreach (var CurrentConnection in _connections.Values)
{
if (CurrentConnection.UName.ToLower() == Username.ToLower())
{
UsernameFound = true;
if (IsConnectionAdmin(CurrentConnection)) MessageToUCID(MSO.UCID, "^7" + CurrentConnection.PName + " ^3is already an admin");
else
{
CurrentConnection.IsCustomAdmin = true;
StreamReader ApR = new StreamReader(SaveDataFolder + "/admins.ini");
string TempAPR = ApR.ReadToEnd();
ApR.Close();
StreamWriter Ap = new StreamWriter(SaveDataFolder + "/admins.ini");
Ap.WriteLine(TempAPR + CurrentConnection.UName);
Ap.Flush();
Ap.Close();
}
break;
}
}
if (UsernameFound == false) MessageToUCID(MSO.UCID, Username + " ^3not found");
}
private void OnPlayerJoin(InSim insim, IS_NPL NPL)
{
try
{
if (_players.ContainsKey(NPL.PLID))
{
// Leaving pits, just update NPL object.
_players[NPL.PLID].PLID = NPL.PLID;
_players[NPL.PLID].PName = NPL.PName;
}
else
{
// Add new player.
_players.Add(NPL.PLID, new Players
{
PLID = NPL.PLID,
PName = NPL.PName
});
}
}
catch (Exception EX) {}
}
private void OnPlayerSpectate(InSim insim, IS_PLL PLL)
{
try { _players.Remove(PLL.PLID); }
catch (Exception EX) {}
}
private void OnPlayerRename(InSim insim, IS_CPR CPR)
{
try
{
_connections[CPR.UCID].PName = CPR.PName;
foreach (var CurrentPlayer in _players.Values) if (CurrentPlayer.UCID == CPR.UCID) CurrentPlayer.PName = CPR.PName;
}
catch (Exception EX) {}
}
_players[con.A.PLID].PName//This is the player name.
private Dictionary<byte, Connections> _connections = new Dictionary<byte, Connections>();
const string SaveDataFolder = "files";
private void LogTextToFile(string file, string text, bool AdminMessage = true)
{
//Console.WriteLine(file + ": {0}", text); You dont need this one as you use form application.
if (AdminMessage == true) MessageToAdmins("There was a " + file + " : " + text);
if (System.IO.File.Exists(SaveDataFolder + "/" + file + ".log") == false) { FileStream CurrentFile = System.IO.File.Create(SaveDataFolder + "/" + file + ".log"); CurrentFile.Close(); }
StreamReader TextTempData = new StreamReader(SaveDataFolder + "/"+ file + ".log");
string TempText = TextTempData.ReadToEnd();
TextTempData.Close();
StreamWriter TextData = new StreamWriter(SaveDataFolder + "/" + file + ".log");
TextData.WriteLine(TempText + DateTime.Now + ": " + text);
TextData.Flush();
TextData.Close();
}
private void MessageToAdmins(string Message)
{
foreach (var CurrentConnection in _connections.Values)
{
if (CurrentConnection.IsAdmin == true) MessageToUCID(CurrentConnection.UCID, Message);
}
}
class Connections//Somewhere at the top of your code
{
public byte UCID;
public string UName;
public string PName;
public bool IsAdmin;
}
//Before "insim.Initialize(new InSimSettings blablabla"
insim.Bind<IS_NCN>(OnConnectionJoin);
insim.Bind<IS_CNL>(OnConnectionLeave);
//Add these anywhere you want
private void OnConnectionJoin(InSim insim, IS_NCN NCN)
{
try
{
_connections.Add(NCN.UCID, new Connections
{
UCID = NCN.UCID,
UName = NCN.UName,
PName = NCN.PName,
IsAdmin = NCN.Admin,
});
}
catch (Exception EX) { LogTextToFile("packetError", "NCN - " + EX.Message); }
}
private void OnConnectionLeave(InSim insim, IS_CNL CNL)
{
try { _connections.Remove(CNL.UCID); }
catch (Exception EX) { LogTextToFile("packetError", "CNL - " + EX.Message); }
}
case "!ialwaysforget":
insim.Send("/msg ^3" + _connections[mso.UCID].PName + " always forget his username which is " + _connections[mso.UCID].UName);
break;
private void SendRCMToUsername(string Username, string Text, int Duration)
{
insim.Send("/rcm " + Text);
insim.Send("/rcm_ply " + Username);
Timer timer = new Timer { Interval = Duration, AutoReset = false };
timer.Interval = Duration;
timer.Elapsed += delegate { ClearRCMFromUsername(Username); };
timer.Start();
}
private void ClearRCMFromUsername(string Username)
{
insim.Send("/rcc_ply " + Username);
}
SendRCMToUsername("DarkKostas", "^1Hi Mom", 5000);