Skip to content

Commit

Permalink
Added config support for GameServer port and ip (basically, one serve…
Browse files Browse the repository at this point in the history
…r has the node.js server, the other has scpsl)
  • Loading branch information
VirtualBrightPlayz committed Nov 17, 2018
1 parent 0bb9b87 commit 100fd72
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
Binary file removed .vs/Mod8/v15/.suo
Binary file not shown.
Empty file.
Binary file removed .vs/Mod8/v15/Server/sqlite3/storage.ide
Binary file not shown.
2 changes: 1 addition & 1 deletion Mod8/Mod8.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public override void OnEnable()
this.Info("Mod8 plugin enabled.");
this.Info("Connecting to node.js server");
tcp = new TcpClient();
tcp.Connect(this.GetConfigString("tcpmapip"), this.GetConfigInt("tcpmapport"));
tcp.Connect(ConfigManager.Manager.Config.GetStringValue("tcpmapip", "127.0.0.1"), ConfigManager.Manager.Config.GetIntValue("tcpmapport", 8080));
s = tcp.GetStream();
rm = new RoomManager();
}
Expand Down
24 changes: 20 additions & 4 deletions Mod8/Mod8EventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ public Mod8EventHandler(Plugin mod8)

void IEventHandlerPlayerJoin.OnPlayerJoin(PlayerJoinEvent ev)
{
if (keys.ContainsKey(ev.Player.SteamId))
/*if (keys.ContainsKey(ev.Player.SteamId))
{
ev.Player.SendConsoleMessage("Your SteamID is: " + ev.Player.SteamId);
ev.Player.SendConsoleMessage("Your key is: " + keys[ev.Player.SteamId]);
return;
}
}*/
string newkey = "";
for (int i = 0; i < 5; i++)
{
Expand Down Expand Up @@ -87,6 +87,14 @@ void IEventHandlerFixedUpdate.OnFixedUpdate(FixedUpdateEvent ev)
{
var mod8 = (Mod8)plugin;

if (!mod8.tcp.Connected || !mod8.s.CanWrite)
{
mod8.tcp.Close();
mod8.tcp = new System.Net.Sockets.TcpClient();
mod8.tcp.Connect(ConfigManager.Manager.Config.GetStringValue("tcpmapip", "127.0.0.1"), ConfigManager.Manager.Config.GetIntValue("tcpmapport", 8080));
mod8.s = mod8.tcp.GetStream();
}

string str = string.Empty;
str += " { ";
str += " \"lczrooms\": [ ";
Expand Down Expand Up @@ -173,6 +181,7 @@ void IEventHandlerFixedUpdate.OnFixedUpdate(FixedUpdateEvent ev)
{
var play = pls[i];
GameObject obj = (GameObject)pls[i].GetGameObject();

str += " { ";

str += " \"posx\": \"" + obj.transform.position.x.ToString() + "\", ";
Expand All @@ -187,7 +196,14 @@ void IEventHandlerFixedUpdate.OnFixedUpdate(FixedUpdateEvent ev)
str += " \"role\": \"" + play.TeamRole.Role.ToString() + "\", ";
str += " \"ip\": \"" + play.IpAddress + "\", ";
str += " \"steamid\": \"" + play.SteamId + "\", ";
str += " \"key\": \"" + keys[play.SteamId] + "\", ";
if (keys.ContainsKey(play.SteamId))
{
str += " \"key\": \"" + keys[play.SteamId] + "\", ";
}
else
{
str += " \"key\": \"errorfindingkey\", ";
}
str += " \"name\": \"" + play.Name + "\" ";
if (i + 1 >= pls.Count)
{
Expand All @@ -208,7 +224,7 @@ void IEventHandlerFixedUpdate.OnFixedUpdate(FixedUpdateEvent ev)
}
catch (Exception e)
{
plugin.Info(e.Message);
plugin.Info(e.StackTrace);
}
}
}
Expand Down

0 comments on commit 100fd72

Please sign in to comment.