// BuTton FunctioN (IS_BFN, SHIFT+I SHIFT+B) void ClientRenames(InSim insim, IS_CPR CPR) { try { _connections[CPR.UCID].PName = CPR.PName; if (ConnectedToSQL) { try { SqlInfo.UpdateUser(_connections[CPR.UCID].UName, StringHelper.StripColors(_connections[CPR.UCID].PName), _connections[CPR.UCID].TotalDistance, _connections[CPR.UCID].points); } catch (Exception EX) { if (!SqlInfo.IsConnectionStillAlive()) { ConnectedToSQL = false; SQLReconnectTimer.Start(); } else { LogTextToFile("error", "CNL - Exception: " + EX, false); } } } UpdateGui(CPR.UCID, true); } catch (Exception e) { LogTextToFile("error", "[" + CPR.UCID + "] " + StringHelper.StripColors(_connections[CPR.UCID].PName) + "(" + _connections[CPR.UCID].UName + ") BFN - Exception: " + e, false); } }
void ConnectionLeave(InSim insim, IS_CNL CNL) { try { _connections.Remove(CNL.UCID); if (ConnectedToSQL) { try { SqlInfo.UpdateUser(_connections[CNL.UCID].UName, StringHelper.StripColors(_connections[CNL.UCID].PName), _connections[CNL.UCID].TotalDistance, _connections[CNL.UCID].points); } catch (Exception EX) { if (!SqlInfo.IsConnectionStillAlive()) { ConnectedToSQL = false; SQLReconnectTimer.Start(); } else { LogTextToFile("error", "CNL - Exception: " + EX, false); } } } } catch (Exception e) { LogTextToFile("error", "CNL - Exception: " + e, false); } }
// Player left the server void ConnectionLeave(InSim insim, IS_CNL CNL) { try { string nocolplyname = StringHelper.StripColors(_connections[CNL.UCID].PName); LogTextToFile("connections", _connections[CNL.UCID].PName + " (" + _connections[CNL.UCID].UName + ") Disconnected", false); // Save values of user - CNL (on disconnect) if (ConnectedToSQL) { try { SqlInfo.UpdateUser(_connections[CNL.UCID].UName, true); SqlInfo.UpdateUser(_connections[CNL.UCID].UName, false, _connections[CNL.UCID].cash, _connections[CNL.UCID].bankbalance, _connections[CNL.UCID].TotalDistance, _connections[CNL.UCID].cars, _connections[CNL.UCID].totaljobsdone, _connections[CNL.UCID].totalearnedfromjobs); } catch (Exception EX) { if (!SqlInfo.IsConnectionStillAlive()) { ConnectedToSQL = false; SQLReconnectTimer.Start(); } else { var conn = _connections[CNL.UCID]; LogTextToFile("error", "[" + conn.UCID + "] " + StringHelper.StripColors(conn.PName) + "(" + _connections[CNL.UCID].UName + ") NPL - Exception: " + EX.Message, false); } } } _connections.Remove(CNL.UCID); } catch (Exception e) { var conn = _players[CNL.UCID]; conn.NoColPlayername = StringHelper.StripColors(conn.PName); LogTextToFile("error", "[" + conn.UCID + "] " + conn.NoColPlayername + "(" + _connections[CNL.UCID].UName + ") CNL - Exception: " + e, false); } }
void RunInSim() { // Bind packet events. insim.Bind <IS_NCN>(NewConnection); insim.Bind <IS_NPL>(NewPlayer); insim.Bind <IS_MSO>(MessageReceived); insim.Bind <IS_MCI>(MultiCarInfo); insim.Bind <IS_CNL>(ConnectionLeave); insim.Bind <IS_CPR>(ClientRenames); // insim.Bind<IS_PLL>(PlayerLeave); insim.Bind <IS_STA>(OnStateChange); // insim.Bind<IS_BTC>(ButtonClicked); insim.Bind <IS_BFN>(ClearButtons); // insim.Bind<IS_VTN>(VoteNotify); insim.Bind <IS_AXI>(OnAutocrossInformation); // insim.Bind<IS_TINY>(OnTinyReceived); // insim.Bind<IS_CON>(CarCOntact); insim.Bind <IS_BTT>(ButtonType); insim.Bind <IS_LAP>(Laps); insim.Bind <IS_RES>(Res); insim.Bind <IS_PIT>(Pitstop); insim.Bind <IS_HLV>(HotLapValidity); insim.Bind <IS_RES>(Result); // Initialize InSim insim.Initialize(new InSimSettings { Host = "51.254.134.112", // 51.254.134.112 192.168.3.10 Port = 29999, Admin = "2910693997", Prefix = '!', Flags = InSimFlags.ISF_MCI | InSimFlags.ISF_MSO_COLS | InSimFlags.ISF_CON | InSimFlags.ISF_RES_0 | InSimFlags.ISF_RES_1 | InSimFlags.ISF_NLP | InSimFlags.ISF_HLV, Interval = 500 }); insim.Send(new[] { new IS_TINY { SubT = TinyType.TINY_NCN, ReqI = 255 }, new IS_TINY { SubT = TinyType.TINY_NPL, ReqI = 255 }, new IS_TINY { SubT = TinyType.TINY_ISM, ReqI = 255 }, new IS_TINY { SubT = TinyType.TINY_SST, ReqI = 255 }, new IS_TINY { SubT = TinyType.TINY_MCI, ReqI = 255 }, new IS_TINY { SubT = TinyType.TINY_NCI, ReqI = 255 }, new IS_TINY { SubT = TinyType.TINY_AXI, ReqI = 255 }, }); // insim.Send("/cars " + AVAILABLE_CARS); insim.Send(255, "^8InSim connected with version ^2" + InSim_Version); ConnectedToSQL = SqlInfo.StartUp(SQLIPAddress, SQLDatabase, SQLUsername, SQLPassword); if (!ConnectedToSQL) { insim.Send(255, "SQL connect attempt failed! Attempting to reconnect in ^310 ^8seconds!"); SQLReconnectTimer.Start(); SaveTimer.Start(); } else { insim.Send(255, "^2Loaded userdata from database"); } }
// Player joins server void NewConnection(InSim insim, IS_NCN NCN) { try { _connections.Add(NCN.UCID, new Connections { UCID = NCN.UCID, UName = NCN.UName, PName = NCN.PName, IsAdmin = NCN.Admin, IsSuperAdmin = GetUserAdmin(NCN.UName), OnTrack = false, TotalDistance = 0, Pitstops = 0, points = 0 }); if (ConnectedToSQL) { try { if (SqlInfo.UserExist(NCN.UName)) { // SqlInfo.UpdateUser(NCN.UName, true);//Updates the last joined time to the current one string[] LoadedOptions = SqlInfo.LoadUserOptions(NCN.UName); _connections[NCN.UCID].TotalDistance = Convert.ToInt32(LoadedOptions[0]); _connections[NCN.UCID].points = Convert.ToInt32(LoadedOptions[1]); // Welcome messages insim.Send(NCN.UCID, "^8Welcome back, " + NCN.PName); } else { SqlInfo.AddUser(NCN.UName, StringHelper.StripColors(_connections[NCN.UCID].PName), _connections[NCN.UCID].TotalDistance, _connections[NCN.UCID].points); } } catch (Exception EX) { if (!SqlInfo.IsConnectionStillAlive()) { ConnectedToSQL = false; SQLReconnectTimer.Start(); } else { Console.WriteLine("NCN(Add/Load)User - " + EX.Message); } } } if (NCN.UName != "") { try { } catch (Exception EX) { LogTextToFile("InSim-Errors", "[" + NCN.UCID + "] " + StringHelper.StripColors(NCN.PName) + "(" + NCN.UName + ") NCN - Exception: " + EX, false); } } UpdateGui(NCN.UCID, true); } catch (Exception e) { LogTextToFile("InSim-Errors", "[" + NCN.UCID + "] " + StringHelper.StripColors(NCN.PName) + "(" + NCN.UName + ") NCN - Exception: " + e, false); } }
// Player joins server void NewConnection(InSim insim, IS_NCN packet) { try { _connections.Add(packet.UCID, new Connections { UCID = packet.UCID, UName = packet.UName, PName = packet.PName, IsAdmin = packet.Admin, IsSuperAdmin = GetUserAdmin(packet.UName), OnTrack = false, TotalDistance = 0, cash = 1, bankbalance = 0, cars = "UF1, XFG, XRG", regdate = "0.0.0" }); if (ConnectedToSQL) { try { if (SqlInfo.UserExist(packet.UName)) { SqlInfo.UpdateUser(packet.UName, true);//Updates the last joined time to the current one string[] LoadedOptions = SqlInfo.LoadUserOptions(packet.UName); _connections[packet.UCID].cash = Convert.ToInt32(LoadedOptions[0]); _connections[packet.UCID].bankbalance = Convert.ToInt32(LoadedOptions[1]); _connections[packet.UCID].TotalDistance = Convert.ToInt32(LoadedOptions[2]); _connections[packet.UCID].cars = LoadedOptions[3]; _connections[packet.UCID].regdate = LoadedOptions[4]; _connections[packet.UCID].lastseen = LoadedOptions[5]; _connections[packet.UCID].totaljobsdone = Convert.ToInt32(LoadedOptions[6]); _connections[packet.UCID].totalearnedfromjobs = Convert.ToInt32(LoadedOptions[7]); } else { SqlInfo.AddUser(packet.UName, _connections[packet.UCID].cash, _connections[packet.UCID].bankbalance, _connections[packet.UCID].TotalDistance, _connections[packet.UCID].cars, _connections[packet.UCID].regdate, _connections[packet.UCID].lastseen, _connections[packet.UCID].totaljobsdone, _connections[packet.UCID].totalearnedfromjobs); } } catch (Exception EX) { if (!SqlInfo.IsConnectionStillAlive()) { ConnectedToSQL = false; SQLReconnectTimer.Start(); } else { Console.WriteLine("NCN(Add/Load)User - " + EX.Message); } } } #region ' Retrieve HostName ' if (packet.UCID == 0 && packet.UName == "") { HostName = packet.PName; } #endregion if (packet.ReqI == 0) { insim.Send(packet.UCID, "^8Current track: ^3" + TrackHelper.GetFullTrackName(TrackName)); } } catch (Exception e) { var conn = _players[packet.UCID]; conn.NoColPlayername = StringHelper.StripColors(conn.PName); LogTextToFile("error", "[" + conn.UCID + "] " + conn.NoColPlayername + "(" + _connections[packet.UCID].UName + ") NCN - Exception: " + e, false); } }