2018-12-14 14:08:07 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Net.NetworkInformation;
|
|
|
|
|
using System.Net.Sockets;
|
|
|
|
|
using System.Text;
|
2019-01-04 16:44:07 +01:00
|
|
|
|
using System.Threading;
|
2018-12-14 14:08:07 +01:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace go01
|
|
|
|
|
{
|
|
|
|
|
public partial class CreerPartieReseau_serv : Form
|
|
|
|
|
{
|
2019-01-03 11:20:16 +01:00
|
|
|
|
socketPlateauSRV serveur;
|
2018-12-14 14:08:07 +01:00
|
|
|
|
|
|
|
|
|
public CreerPartieReseau_serv()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
this.tbUid.Text = Guid.NewGuid().ToString();
|
|
|
|
|
this.tbUid.Select(0, 0);
|
2019-01-03 11:20:16 +01:00
|
|
|
|
socketPlateauBase.net_adapters(cbNic);
|
2018-12-14 14:08:07 +01:00
|
|
|
|
//serveur = new socketPlateau()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnCreatePart_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
btnCreatePart.Enabled = false;
|
|
|
|
|
tbPartName.Enabled = false;
|
|
|
|
|
tbNomJoeur.Enabled = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var startTimeSpan = TimeSpan.Zero;
|
|
|
|
|
var periodTimeSpan = TimeSpan.FromSeconds(5);
|
2019-01-04 11:28:58 +01:00
|
|
|
|
Goban.ConfigGo_S config = new Goban.ConfigGo_S(tbPartName.Text, "", tbNomJoeur.Text, int.Parse(tbTaille.Text), int.Parse(tbPionaAligner.Text), IPAddress.Parse(tbIp.Text), int.Parse(tbPort.Text));
|
2019-01-04 16:44:07 +01:00
|
|
|
|
serveur = new socketPlateauSRV(config, null, new socketPlateauSRV.OnConnected(ConnectionEtablie));
|
2018-12-14 14:08:07 +01:00
|
|
|
|
serveur.AttenteJoueur();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2019-01-04 16:44:07 +01:00
|
|
|
|
private void ConnectionEtablie(object o, socketPlateauConnected e)
|
2018-12-14 14:08:07 +01:00
|
|
|
|
{
|
2019-01-04 11:28:58 +01:00
|
|
|
|
Console.WriteLine($"{e.ConfigGo.NomJoeurBlanc} vs {e.ConfigGo.NomJoeurNoir}");
|
2019-01-04 16:44:07 +01:00
|
|
|
|
//serveur.senCmd("");
|
2018-12-17 15:13:05 +01:00
|
|
|
|
Console.WriteLine("CONNETION ETABLEIE");
|
2019-01-04 16:44:07 +01:00
|
|
|
|
Plateau p = new Plateau(e.ConfigGo,serveur);
|
2019-01-03 11:20:16 +01:00
|
|
|
|
//this.Hide();
|
2019-01-04 16:44:07 +01:00
|
|
|
|
|
|
|
|
|
Thread t2 = new Thread(delegate ()
|
|
|
|
|
{
|
|
|
|
|
p.ShowDialog();
|
|
|
|
|
});
|
|
|
|
|
t2.Start();
|
2019-01-03 11:20:16 +01:00
|
|
|
|
//this.Close();
|
2018-12-14 14:08:07 +01:00
|
|
|
|
}
|
|
|
|
|
private void broadcast()
|
|
|
|
|
{
|
|
|
|
|
var Client = new UdpClient();
|
|
|
|
|
var RequestData = Encoding.ASCII.GetBytes($"{tbUid.Text};{tbPartName.Text};{tbNomJoeur.Text};{tbTaille.Text};{tbPionaAligner.Text}");
|
|
|
|
|
|
|
|
|
|
Client.EnableBroadcast = true;
|
|
|
|
|
Client.Send(RequestData, RequestData.Length, new IPEndPoint(IPAddress.Broadcast, 8888));
|
|
|
|
|
|
|
|
|
|
Client.Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void cbNic_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var local = NetworkInterface.GetAllNetworkInterfaces().Where(i => i.Name == cbNic.SelectedItem.ToString()).FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (UnicastIPAddressInformation ip in local.GetIPProperties().UnicastAddresses)
|
|
|
|
|
{
|
|
|
|
|
if (ip.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
|
|
|
|
|
{
|
|
|
|
|
tbIp.Text = ip.Address.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|