Danbias/Code/Game/LanServer/StandAloneLauncher/Form1.cs

112 lines
4.0 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();
2014-02-18 13:12:08 +01:00
this.gameModes.SelectedIndex = 0;
}
public bool Initiate()
{
this.gameServer = new StandaloneGameServerCLI();
return true;
}
public void Run()
{
while (this.Created)
{
Application.DoEvents();
//Do some stuff
this.gameServer.ServerUpdate();
2014-02-18 13:12:08 +01:00
this.labelClientsConnected.Text = "Clients connected: " + this.gameServer.GetClientsConnectedCount().ToString();
}
}
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";
this.ServerInfoTextArea.AppendText(DateTime.Now.ToUniversalTime() + "\n\t" + "Server terminated!\n");
this.panel_commands.Visible = false;
}
else
{
ServerInitDesc desc = new ServerInitDesc();
//desc.mainOptions.broadcast = this.lanBroadcast.Checked;
desc.mainOptions.listenPort = (int)this.listenPort.Value;
desc.mainOptions.serverName = this.serverName.Text;
if (this.gameServer.ServerInitiate(desc) == DanBiasServerReturn.DanBiasServerReturn_Sucess)
{
this.serverIsRunning = true;
GameServerInfo info = this.gameServer.ServerGetInfo();
this.Text = this.serverName.Text + " - " + info.serverIp;
this.listenPort.Enabled = false;
this.serverName.Enabled = false;
this.lanBroadcast.Enabled = false;
this.serverToggle.Text = "Stop server";
this.gameServer.ServerStart();
this.panel_commands.Visible = true;
this.ServerInfoTextArea.AppendText(DateTime.Now.ToUniversalTime() + "\n\t" + "Server initiated!\n\tListening on port " + this.listenPort.Value.ToString() + "\n\tLocal IP: " + info.serverIp + "\n");
}
else
{
this.ServerInfoTextArea.AppendText(DateTime.Now.ToUniversalTime() + "\n\t" + "Failed to initiate the server!");
}
}
2014-02-14 10:46:23 +01:00
}
private void buttonStartGame_Click(object sender, EventArgs e)
{
//this.gameServer.GameSetGameMode(this.gameModes.SelectedText);
this.gameServer.GameSetGameTime((int)this.timeLimit.Value);
//this.gameServer.GameSetMapId(0);
this.gameServer.GameSetMaxClients((int)this.nrOfClients.Value);
2014-02-18 13:12:08 +01:00
if (!this.gameServer.GameStart( this.forceStart.Checked ))
{
this.ServerInfoTextArea.AppendText(DateTime.Now.ToUniversalTime() + "\n\t" + "Failed to start the game session!\n");
}
else
{
this.ServerInfoTextArea.AppendText(DateTime.Now.ToUniversalTime() + "\n\t" + "Game session started!\n");
}
}
2014-02-18 13:12:08 +01:00
private void FormClosingEvent(object sender, FormClosingEventArgs e)
{
if (serverIsRunning)
{
this.gameServer.ServerStop();
}
}
2014-02-14 10:46:23 +01:00
}
}