Minor server contact layer changes for online battles.

This commit is contained in:
MichaelTheShifter 2016-06-26 20:16:27 -04:00
parent 5916d35ac0
commit a067684f08
2 changed files with 42 additions and 35 deletions

View file

@ -387,25 +387,32 @@ private void btnjoinlobby_Click(object sender, EventArgs e)
{ {
lbonlineservers.Hide(); lbonlineservers.Hide();
API.CurrentSave.MyOnlineNetwork.Codepoints = API.Codepoints; API.CurrentSave.MyOnlineNetwork.Codepoints = API.Codepoints;
Package_Grabber.SendMessage(selected_server.IPAddress, "join_lobby", API.CurrentSave.MyOnlineNetwork); Package_Grabber.SendMessage(selected_server.IPAddress, $"join_lobby {JsonConvert.SerializeObject(API.CurrentSave.MyOnlineNetwork)}");
Online.Hacking.Matchmaker.Matchmake(selected_server); Online.Hacking.Matchmaker.Matchmake(selected_server);
var t = new System.Windows.Forms.Timer(); var t = new System.Windows.Forms.Timer();
t.Interval = 5000; t.Interval = 5000;
int sindex = 0; int sindex = 0;
t.Tick += (o, a) => t.Tick += (o, a) =>
{ {
SetupSidePane(Online.Hacking.Matchmaker.Players[sindex]); try
if (Matchmaker.Players.Count > 1)
{ {
if (sindex < Online.Hacking.Matchmaker.Players.Count - 1) SetupSidePane(Online.Hacking.Matchmaker.Players[sindex]);
if (Matchmaker.Players.Count > 1)
{ {
sindex = 0; if (sindex < Online.Hacking.Matchmaker.Players.Count - 1)
} {
else sindex = 0;
{ }
sindex += 1; else
{
sindex += 1;
}
} }
} }
catch
{
}
}; };
t.Start(); t.Start();
} }
@ -437,7 +444,7 @@ private void stop_matchmake(object sender, FormClosingEventArgs e)
{ {
if(selected_server != null) if(selected_server != null)
{ {
Package_Grabber.SendMessage(selected_server.IPAddress, $"leave_lobby", API.CurrentSave.MyOnlineNetwork); Package_Grabber.SendMessage(selected_server.IPAddress, $"leave_lobby {JsonConvert.SerializeObject(API.CurrentSave.MyOnlineNetwork)}");
} }
} }

View file

@ -33,7 +33,7 @@ public static void Initiate()
var om = (e.Data.Object as ObjectModel); var om = (e.Data.Object as ObjectModel);
if(om.Command == "server_info") if(om.Command == "server_info")
{ {
var si = om.OptionalObject as ServerInfo; var si = JsonConvert.DeserializeObject<ServerInfo>(om.OptionalObject as string);
si.IPAddress = c.Value.RemoteHost; si.IPAddress = c.Value.RemoteHost;
Servers.Add(si); Servers.Add(si);
invoke(() => invoke(() =>
@ -70,13 +70,13 @@ public static void Matchmake(ServerInfo si)
{ {
try try
{ {
if (Players[index] != API.CurrentSave.MyOnlineNetwork && Players[index].Name != null) if (Players[index].Name != API.CurrentSave.MyOnlineNetwork.Name && Players[index].Name != null)
{ {
SelectedNetwork = Players[index]; SelectedNetwork = Players[index];
MakerTimer.Stop(); MakerTimer.Stop();
SelectedNetworkListener = new NetListener(si, SelectedNetwork); SelectedNetworkListener = new NetListener(si, SelectedNetwork);
SelectedNetworkTransmitter = new NetTransmitter(si, SelectedNetwork); SelectedNetworkTransmitter = new NetTransmitter(si, SelectedNetwork);
Package_Grabber.SendMessage(SelectedServer.IPAddress, $"leave_lobby", API.CurrentSave.MyOnlineNetwork); Package_Grabber.SendMessage(SelectedServer.IPAddress, $"leave_lobby {JsonConvert.SerializeObject(API.CurrentSave.MyOnlineNetwork)}");
} }
else else
{ {
@ -120,29 +120,29 @@ private void register_events(ServerInfo si, Network net)
{ {
if(e.Data.Object is string) if(e.Data.Object is string)
{ {
string data = e.Data.Object as string; var data = JsonConvert.DeserializeObject<ObjectModel>(e.Data.Object as string);
string[] args = data.Split(' '); string[] args = data.Command.Split(' ');
if (args[1] == net.Name + ";" + net.Description) { if ((data.OptionalObject as Network) == net) {
switch (args[0].ToLower()) switch (args[0].ToLower())
{ {
case "set_health": case "set_health":
string hn = args[2]; string hn = args[1];
int hp = Convert.ToInt32(args[3]); int hp = Convert.ToInt32(args[2]);
invoke(() => { ModuleHealthSet?.Invoke(this, new Events.Health { host_name = hn, health = hp }); }); invoke(() => { ModuleHealthSet?.Invoke(this, new Events.Health { host_name = hn, health = hp }); });
break; break;
case "place_module": case "place_module":
string hostname = args[2]; string hostname = args[1];
int grade = Convert.ToInt32(args[3]); int grade = Convert.ToInt32(args[2]);
int newhp = Convert.ToInt32(args[4]); int newhp = Convert.ToInt32(args[3]);
int x = Convert.ToInt32(args[5]); int x = Convert.ToInt32(args[4]);
int y = Convert.ToInt32(args[6]); int y = Convert.ToInt32(args[5]);
int type = Convert.ToInt32(args[7]); int type = Convert.ToInt32(args[6]);
var moduleToPlace = new Module { Grade = grade, Hostname = hostname, HP = newhp, Type = type, X = x, Y = y }; var moduleToPlace = new Module { Grade = grade, Hostname = hostname, HP = newhp, Type = type, X = x, Y = y };
MyModules.Add(moduleToPlace); MyModules.Add(moduleToPlace);
invoke(() => { ModulePlaced?.Invoke(this, new Events.ModulePlaced { new_module = moduleToPlace }); }); invoke(() => { ModulePlaced?.Invoke(this, new Events.ModulePlaced { new_module = moduleToPlace }); });
break; break;
case "remove_module": case "remove_module":
string hostnametoremove = args[2]; string hostnametoremove = args[1];
var m = new Module(); var m = new Module();
foreach (var mod in MyModules) foreach (var mod in MyModules)
{ {
@ -158,15 +158,15 @@ private void register_events(ServerInfo si, Network net)
case "upgrade": case "upgrade":
invoke(() => invoke(() =>
{ {
string hostnametoupgrade = args[2]; string hostnametoupgrade = args[1];
int newgrade = Convert.ToInt32(args[3]); int newgrade = Convert.ToInt32(args[2]);
ModuleUpgraded?.Invoke(this, new Events.ModuleUpgraded { hostname = hostnametoupgrade, grade = newgrade }); ModuleUpgraded?.Invoke(this, new Events.ModuleUpgraded { hostname = hostnametoupgrade, grade = newgrade });
}); });
break; break;
case "disable": case "disable":
invoke(() => invoke(() =>
{ {
string name = args[2]; string name = args[1];
ModuleDisabled?.Invoke(this, new Events.Disabled { hostName = name }); ModuleDisabled?.Invoke(this, new Events.Disabled { hostName = name });
}); });
break; break;
@ -191,11 +191,11 @@ public void invoke(Action method)
public class NetTransmitter public class NetTransmitter
{ {
public ServerInfo serverInfo = null; public ServerInfo serverInfo = null;
public string EnemyIdent = ""; public Network EnemyIdent = null;
public NetTransmitter(ServerInfo si, Network enemy) public NetTransmitter(ServerInfo si, Network enemy)
{ {
EnemyIdent = enemy.Name + ";" + enemy.Description; EnemyIdent = enemy;
serverInfo = si; serverInfo = si;
var h = new HackUI(this, Matchmaker.SelectedNetworkListener); var h = new HackUI(this, Matchmaker.SelectedNetworkListener);
h.Show(); h.Show();
@ -208,23 +208,23 @@ public void send_message(Messages msg, object value)
{ {
case Messages.PlaceModule: case Messages.PlaceModule:
var m = value as Module; var m = value as Module;
Package_Grabber.SendMessage(serverInfo.IPAddress, $"place_module {EnemyIdent} {m.Hostname} {m.Grade} {m.HP} {m.X} {m.Y} {m.Type}"); Package_Grabber.SendMessage(serverInfo.IPAddress, $"place_module {m.Hostname} {m.Grade} {m.HP} {m.X} {m.Y} {m.Type}", EnemyIdent);
break; break;
case Messages.Upgrade: case Messages.Upgrade:
string upgradestr = value as string; string upgradestr = value as string;
Package_Grabber.SendMessage(serverInfo.IPAddress, $"upgrade {EnemyIdent} {upgradestr}"); Package_Grabber.SendMessage(serverInfo.IPAddress, $"upgrade {upgradestr}", EnemyIdent);
break; break;
case Messages.RemoveModule: case Messages.RemoveModule:
string hostnametoremove = value as string; string hostnametoremove = value as string;
Package_Grabber.SendMessage(serverInfo.IPAddress, $"remove_module {EnemyIdent} {hostnametoremove}"); Package_Grabber.SendMessage(serverInfo.IPAddress, $"remove_module {hostnametoremove}", EnemyIdent);
break; break;
case Messages.SetHealth: case Messages.SetHealth:
string healthsetstr = value as string; string healthsetstr = value as string;
Package_Grabber.SendMessage(serverInfo.IPAddress, $"set_health {EnemyIdent} {healthsetstr}"); Package_Grabber.SendMessage(serverInfo.IPAddress, $"set_health {healthsetstr}", EnemyIdent);
break; break;
case Messages.Disabled: case Messages.Disabled:
string hnamestr = value as string; string hnamestr = value as string;
Package_Grabber.SendMessage(serverInfo.IPAddress, $"disable {EnemyIdent} {hnamestr}"); Package_Grabber.SendMessage(serverInfo.IPAddress, $"disable {hnamestr}", EnemyIdent);
break; break;
} }
} }