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,12 +387,14 @@ private void btnjoinlobby_Click(object sender, EventArgs e)
{
lbonlineservers.Hide();
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);
var t = new System.Windows.Forms.Timer();
t.Interval = 5000;
int sindex = 0;
t.Tick += (o, a) =>
{
try
{
SetupSidePane(Online.Hacking.Matchmaker.Players[sindex]);
if (Matchmaker.Players.Count > 1)
@ -406,6 +408,11 @@ private void btnjoinlobby_Click(object sender, EventArgs e)
sindex += 1;
}
}
}
catch
{
}
};
t.Start();
}
@ -437,7 +444,7 @@ private void stop_matchmake(object sender, FormClosingEventArgs e)
{
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);
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;
Servers.Add(si);
invoke(() =>
@ -70,13 +70,13 @@ public static void Matchmake(ServerInfo si)
{
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];
MakerTimer.Stop();
SelectedNetworkListener = new NetListener(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
{
@ -120,29 +120,29 @@ private void register_events(ServerInfo si, Network net)
{
if(e.Data.Object is string)
{
string data = e.Data.Object as string;
string[] args = data.Split(' ');
if (args[1] == net.Name + ";" + net.Description) {
var data = JsonConvert.DeserializeObject<ObjectModel>(e.Data.Object as string);
string[] args = data.Command.Split(' ');
if ((data.OptionalObject as Network) == net) {
switch (args[0].ToLower())
{
case "set_health":
string hn = args[2];
int hp = Convert.ToInt32(args[3]);
string hn = args[1];
int hp = Convert.ToInt32(args[2]);
invoke(() => { ModuleHealthSet?.Invoke(this, new Events.Health { host_name = hn, health = hp }); });
break;
case "place_module":
string hostname = args[2];
int grade = Convert.ToInt32(args[3]);
int newhp = Convert.ToInt32(args[4]);
int x = Convert.ToInt32(args[5]);
int y = Convert.ToInt32(args[6]);
int type = Convert.ToInt32(args[7]);
string hostname = args[1];
int grade = Convert.ToInt32(args[2]);
int newhp = Convert.ToInt32(args[3]);
int x = Convert.ToInt32(args[4]);
int y = Convert.ToInt32(args[5]);
int type = Convert.ToInt32(args[6]);
var moduleToPlace = new Module { Grade = grade, Hostname = hostname, HP = newhp, Type = type, X = x, Y = y };
MyModules.Add(moduleToPlace);
invoke(() => { ModulePlaced?.Invoke(this, new Events.ModulePlaced { new_module = moduleToPlace }); });
break;
case "remove_module":
string hostnametoremove = args[2];
string hostnametoremove = args[1];
var m = new Module();
foreach (var mod in MyModules)
{
@ -158,15 +158,15 @@ private void register_events(ServerInfo si, Network net)
case "upgrade":
invoke(() =>
{
string hostnametoupgrade = args[2];
int newgrade = Convert.ToInt32(args[3]);
string hostnametoupgrade = args[1];
int newgrade = Convert.ToInt32(args[2]);
ModuleUpgraded?.Invoke(this, new Events.ModuleUpgraded { hostname = hostnametoupgrade, grade = newgrade });
});
break;
case "disable":
invoke(() =>
{
string name = args[2];
string name = args[1];
ModuleDisabled?.Invoke(this, new Events.Disabled { hostName = name });
});
break;
@ -191,11 +191,11 @@ public void invoke(Action method)
public class NetTransmitter
{
public ServerInfo serverInfo = null;
public string EnemyIdent = "";
public Network EnemyIdent = null;
public NetTransmitter(ServerInfo si, Network enemy)
{
EnemyIdent = enemy.Name + ";" + enemy.Description;
EnemyIdent = enemy;
serverInfo = si;
var h = new HackUI(this, Matchmaker.SelectedNetworkListener);
h.Show();
@ -208,23 +208,23 @@ public void send_message(Messages msg, object value)
{
case Messages.PlaceModule:
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;
case Messages.Upgrade:
string upgradestr = value as string;
Package_Grabber.SendMessage(serverInfo.IPAddress, $"upgrade {EnemyIdent} {upgradestr}");
Package_Grabber.SendMessage(serverInfo.IPAddress, $"upgrade {upgradestr}", EnemyIdent);
break;
case Messages.RemoveModule:
string hostnametoremove = value as string;
Package_Grabber.SendMessage(serverInfo.IPAddress, $"remove_module {EnemyIdent} {hostnametoremove}");
Package_Grabber.SendMessage(serverInfo.IPAddress, $"remove_module {hostnametoremove}", EnemyIdent);
break;
case Messages.SetHealth:
string healthsetstr = value as string;
Package_Grabber.SendMessage(serverInfo.IPAddress, $"set_health {EnemyIdent} {healthsetstr}");
Package_Grabber.SendMessage(serverInfo.IPAddress, $"set_health {healthsetstr}", EnemyIdent);
break;
case Messages.Disabled:
string hnamestr = value as string;
Package_Grabber.SendMessage(serverInfo.IPAddress, $"disable {EnemyIdent} {hnamestr}");
Package_Grabber.SendMessage(serverInfo.IPAddress, $"disable {hnamestr}", EnemyIdent);
break;
}
}