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 ;
2014-02-16 01:12:27 +01:00
using System.Windows.Interop ;
using System.Runtime.InteropServices ;
2014-02-18 16:38:08 +01:00
using System.Threading ;
using System.Timers ;
2014-02-19 02:10:13 +01:00
using System.IO ;
2014-02-14 10:46:23 +01:00
namespace StandAloneLauncher
{
public partial class Form1 : Form
{
2014-02-16 01:12:27 +01:00
System . Windows . Interop . StandaloneGameServerCLI gameServer ;
bool serverIsRunning = false ;
2014-02-19 02:10:13 +01:00
bool gameIsStarted = false ;
2014-02-16 01:12:27 +01:00
2014-02-14 10:46:23 +01:00
public Form1 ( )
{
InitializeComponent ( ) ;
2014-02-19 02:10:13 +01:00
string [ ] maps = Directory . GetFiles ( "..\\Content\\Worlds\\" ) ;
for ( int i = 0 ; i < maps . Length ; i + + )
{
string temp = maps [ i ] . Split ( '\\' ) . Last ( ) ;
this . mapName . Items . Add ( temp ) ;
}
2014-02-18 13:12:08 +01:00
this . gameModes . SelectedIndex = 0 ;
2014-02-19 02:10:13 +01:00
this . mapName . SelectedIndex = 0 ;
2014-02-16 01:12:27 +01:00
}
public bool Initiate ( )
{
this . gameServer = new StandaloneGameServerCLI ( ) ;
return true ;
}
2014-02-18 16:38:08 +01:00
2014-02-16 01:12:27 +01:00
public void Run ( )
{
while ( this . Created )
{
Application . DoEvents ( ) ;
this . gameServer . ServerUpdate ( ) ;
2014-02-18 13:12:08 +01:00
this . labelClientsConnected . Text = "Clients connected: " + this . gameServer . GetClientsConnectedCount ( ) . ToString ( ) ;
2014-02-16 01:12:27 +01:00
}
}
2014-02-18 16:38:08 +01:00
2014-02-16 01:12:27 +01:00
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" ;
2014-02-17 08:53:15 +01:00
this . ServerInfoTextArea . AppendText ( DateTime . Now . ToUniversalTime ( ) + "\n\t" + "Server terminated!\n" ) ;
this . panel_commands . Visible = false ;
2014-02-19 02:10:13 +01:00
this . panelServerCommands . Visible = false ;
2014-02-16 01:12:27 +01:00
}
else
{
ServerInitDesc desc = new ServerInitDesc ( ) ;
2014-02-17 08:53:15 +01:00
//desc.mainOptions.broadcast = this.lanBroadcast.Checked;
desc . mainOptions . listenPort = ( int ) this . listenPort . Value ;
desc . mainOptions . serverName = this . serverName . Text ;
2014-02-16 01:12:27 +01:00
if ( this . gameServer . ServerInitiate ( desc ) = = DanBiasServerReturn . DanBiasServerReturn_Sucess )
{
2014-02-17 08:53:15 +01:00
this . serverIsRunning = true ;
GameServerInfo info = this . gameServer . ServerGetInfo ( ) ;
this . Text = this . serverName . Text + " - " + info . serverIp ;
2014-02-16 01:12:27 +01:00
this . listenPort . Enabled = false ;
this . serverName . Enabled = false ;
this . lanBroadcast . Enabled = false ;
this . serverToggle . Text = "Stop server" ;
this . gameServer . ServerStart ( ) ;
2014-02-17 08:53:15 +01:00
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" ) ;
2014-02-19 02:10:13 +01:00
this . panelServerCommands . Visible = true ;
2014-02-17 08:53:15 +01:00
}
else
{
this . ServerInfoTextArea . AppendText ( DateTime . Now . ToUniversalTime ( ) + "\n\t" + "Failed to initiate the server!" ) ;
2014-02-16 01:12:27 +01:00
}
}
2014-02-14 10:46:23 +01:00
}
2014-02-17 08:53:15 +01:00
private void buttonStartGame_Click ( object sender , EventArgs e )
{
2014-02-19 02:10:13 +01:00
if ( ! gameIsStarted )
2014-02-17 08:53:15 +01:00
{
2014-02-19 02:10:13 +01:00
//this.gameServer.GameSetGameMode(this.gameModes.SelectedText);
this . gameServer . GameSetGameTime ( ( int ) this . timeLimit . Value ) ;
this . gameServer . GameSetMapName ( this . mapName . Text ) ;
this . gameServer . GameSetMaxClients ( ( int ) this . nrOfClients . Value ) ;
if ( ! ( gameIsStarted = 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" ) ;
this . buttonStartGame . Text = "Stop Game" ;
this . mapName . Enabled = false ;
this . nrOfClients . Enabled = false ;
this . gameModes . Enabled = false ;
this . timeLimit . Enabled = false ;
this . forceStart . Enabled = false ;
}
2014-02-17 08:53:15 +01:00
}
else
{
2014-02-19 02:10:13 +01:00
this . gameIsStarted = false ;
this . buttonStartGame . Text = "Start Game" ;
this . mapName . Enabled = true ;
this . nrOfClients . Enabled = true ;
this . gameModes . Enabled = true ;
this . timeLimit . Enabled = true ;
this . forceStart . Enabled = true ;
2014-02-17 08:53:15 +01:00
}
}
2014-02-18 13:12:08 +01:00
private void FormClosingEvent ( object sender , FormClosingEventArgs e )
{
if ( serverIsRunning )
{
this . gameServer . ServerStop ( ) ;
}
}
2014-02-19 02:10:13 +01:00
private void buttonAddNewDataField_Click ( object sender , EventArgs e )
{
this . dataProtocolFields . RowCount + + ;
this . dataProtocolFields . SetRow ( this . buttonsAtBottom , this . dataProtocolFields . RowCount - 1 ) ;
Panel p = new Panel ( ) ;
p = this . panel2 ;
this . dataProtocolFields . RowStyles . Add ( new RowStyle ( SizeType . Absolute , 27 ) ) ;
}
2014-02-14 10:46:23 +01:00
}
}