Danbias/Code/StandAloneLauncher/Form1.cs

76 lines
2.2 KiB
C#
Raw Normal View History

2014-02-14 10:46:23 +01:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Interop;
using System.Runtime.InteropServices;
2014-02-14 10:46:23 +01:00
namespace StandAloneLauncher
{
public partial class Form1 : Form
{
System.Windows.Interop.StandaloneGameServerCLI gameServer;
bool serverIsRunning = false;
2014-02-14 10:46:23 +01:00
public Form1()
{
InitializeComponent();
}
public bool Initiate()
{
this.gameServer = new StandaloneGameServerCLI();
return true;
}
public void Run()
{
while (this.Created)
{
Application.DoEvents();
//Do some stuff
this.gameServer.ServerUpdate();
}
}
private void button1_serverToggle_Click(object sender, EventArgs e)
{
if (this.serverIsRunning)
{
this.serverIsRunning = false;
this.gameServer.ServerStop();
this.listenPort.Enabled = true;
this.serverName.Enabled = true;
this.lanBroadcast.Enabled = true;
this.serverToggle.Text = "Start server";
}
else
{
this.serverIsRunning = true;
ServerInitDesc desc = new ServerInitDesc();
desc.broadcast = this.lanBroadcast.Checked;
desc.listenPort = (int)this.listenPort.Value;
desc.serverName = this.serverName.Text;
if (this.gameServer.ServerInitiate(desc) == DanBiasServerReturn.DanBiasServerReturn_Sucess)
{
this.listenPort.Enabled = false;
this.serverName.Enabled = false;
this.lanBroadcast.Enabled = false;
this.serverToggle.Text = "Stop server";
this.gameServer.ServerStart();
this.clientInfoBox.Items.Add((Object)"Server initiated!");
}
}
2014-02-14 10:46:23 +01:00
}
}
}