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.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Net.Sockets;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace go01
|
|
|
|
|
{
|
|
|
|
|
public partial class RejoindrePartieReseau_client : Form
|
|
|
|
|
{
|
2019-01-04 11:28:58 +01:00
|
|
|
|
Goban.ConfigGo_S cfg;
|
2018-12-14 14:08:07 +01:00
|
|
|
|
Thread ecouteThread;
|
|
|
|
|
System.Threading.Timer timerTTLdtListPart;
|
|
|
|
|
private DataTable dtListPart;
|
|
|
|
|
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
|
2019-01-04 11:28:58 +01:00
|
|
|
|
Plateau p;
|
2018-12-14 14:08:07 +01:00
|
|
|
|
/*public struct partie_S
|
|
|
|
|
{
|
|
|
|
|
public string uid, partName, joueurAdverseName, ip;
|
|
|
|
|
public int taille, pionAaligner;
|
|
|
|
|
public partie_S(string uid, string partName, string joueurAdverseName, string ip, int taille, int pionAaligner)
|
|
|
|
|
{
|
|
|
|
|
this.uid = uid;
|
|
|
|
|
this.partName = partName;
|
|
|
|
|
this.joueurAdverseName = joueurAdverseName;
|
|
|
|
|
this.taille = taille;
|
|
|
|
|
this.pionAaligner = pionAaligner;
|
|
|
|
|
this.ip = ip;
|
|
|
|
|
}
|
|
|
|
|
public partie_S(string[] s, string ip)
|
|
|
|
|
{
|
|
|
|
|
this.uid = s[0];
|
|
|
|
|
this.partName = s[1];
|
|
|
|
|
this.joueurAdverseName = s[2];
|
|
|
|
|
this.taille = int.Parse(s[3]);
|
|
|
|
|
this.pionAaligner = int.Parse(s[4]);
|
|
|
|
|
this.ip = ip;
|
|
|
|
|
}
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return uid;
|
|
|
|
|
}
|
|
|
|
|
public static implicit operator string(partie_S part)
|
|
|
|
|
{
|
|
|
|
|
return part.ToString();
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
public RejoindrePartieReseau_client()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
dtListPart = new DataTable();
|
|
|
|
|
|
|
|
|
|
dtListPart.Columns.Add("uid", typeof(string));
|
2019-01-04 11:28:58 +01:00
|
|
|
|
dtListPart.Columns.Add("partName", typeof(Goban.ConfigGo_S));
|
2018-12-14 14:08:07 +01:00
|
|
|
|
dtListPart.Columns.Add("playerName", typeof(string));
|
|
|
|
|
dtListPart.Columns.Add("ip", typeof(string));
|
|
|
|
|
dtListPart.Columns.Add("port", typeof(int));//timeStamp
|
|
|
|
|
dtListPart.Columns.Add("timeStamp", typeof(DateTime));
|
|
|
|
|
|
|
|
|
|
ecouteThread = new Thread(() =>
|
|
|
|
|
{
|
|
|
|
|
Thread.CurrentThread.IsBackground = true;
|
|
|
|
|
Listen();
|
|
|
|
|
});
|
|
|
|
|
ecouteThread.Start();
|
|
|
|
|
|
|
|
|
|
var startTimeSpan = TimeSpan.Zero;
|
|
|
|
|
var periodTimeSpan = TimeSpan.FromSeconds(1);
|
|
|
|
|
timerTTLdtListPart = new System.Threading.Timer((ee) =>
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
TTLdtListPart();
|
|
|
|
|
}, null, startTimeSpan, periodTimeSpan);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Listen()
|
|
|
|
|
{
|
|
|
|
|
var Server = new UdpClient(8888);
|
|
|
|
|
while (1==1)
|
|
|
|
|
{
|
|
|
|
|
var ClientEp = new IPEndPoint(IPAddress.Any, 0);
|
|
|
|
|
byte[] ClientRequestData = Server.Receive(ref ClientEp);
|
|
|
|
|
using (MemoryStream ms = new MemoryStream(ClientRequestData))
|
|
|
|
|
{
|
2019-01-04 11:28:58 +01:00
|
|
|
|
Goban.ConfigGo_S cfgGo = (Goban.ConfigGo_S)binaryFormatter.Deserialize(ms);
|
2018-12-14 14:08:07 +01:00
|
|
|
|
Invoke(new Action(() => { ajoutPartie(cfgGo, ClientEp.Address.ToString()); }));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string ClientRequest = Encoding.ASCII.GetString(ClientRequestData);
|
|
|
|
|
Console.WriteLine("Recived {0} from {1}, sending response", ClientRequest, ClientEp.Address.ToString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-04 11:28:58 +01:00
|
|
|
|
public void ajoutPartie(Goban.ConfigGo_S cfgGo, string ip)
|
2018-12-14 14:08:07 +01:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if(dtListPart.Select($"uid = '{cfgGo.Uid}'").Length==0)
|
2019-01-04 11:28:58 +01:00
|
|
|
|
dtListPart.Rows.Add(cfgGo.Uid, cfgGo, cfgGo.NomJoeurBlanc==""? cfgGo.NomJoeurNoir: cfgGo.NomJoeurBlanc, cfgGo.IpServeur, cfgGo.port, DateTime.Now);
|
2018-12-14 14:08:07 +01:00
|
|
|
|
//lock (DgvPart) ;
|
|
|
|
|
dtListPart.Select($"uid = '{cfgGo.Uid}'")[0]["timeStamp"] = DateTime.Now;
|
|
|
|
|
DgvPart.DataSource = dtListPart;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public void TTLdtListPart()
|
|
|
|
|
{
|
|
|
|
|
foreach(DataGridViewRow row in dgvPart.Rows)
|
|
|
|
|
{
|
|
|
|
|
if(((DateTime)row.Cells["timeStamp"].Value).AddSeconds(10) <= DateTime.Now)
|
|
|
|
|
{
|
|
|
|
|
Invoke(new Action(() => {
|
|
|
|
|
dgvPart.Rows.Remove(row);
|
|
|
|
|
dgvPart.Refresh();
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RejoindrePartieReseau_client_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RejoindrePartieReseau_client_FormClosing(object sender, FormClosingEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ecouteThread.Abort();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DataGridView DgvPart
|
|
|
|
|
{
|
|
|
|
|
get { return this.dgvPart; }
|
|
|
|
|
set { }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void dgvPart_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (dgvPart.SelectedRows.Count <= 0)
|
|
|
|
|
return;
|
2019-01-04 11:28:58 +01:00
|
|
|
|
cfg = (Goban.ConfigGo_S)dgvPart.SelectedRows[0].Cells["partName"].Value;
|
2018-12-14 14:08:07 +01:00
|
|
|
|
tbIpServ.Text = cfg.IpServeur.ToString();
|
|
|
|
|
tbPort.Text = cfg.port.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnJoin_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (dgvPart.SelectedRows.Count <= 0)
|
|
|
|
|
return;
|
2019-01-04 11:28:58 +01:00
|
|
|
|
cfg = (Goban.ConfigGo_S)dgvPart.SelectedRows[0].Cells["partName"].Value;
|
|
|
|
|
if(cfg.NomJoeurBlanc == "")
|
|
|
|
|
cfg.NomJoeurBlanc = tbPlayername.Text;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
cfg.NomJoeurBlanc = tbPlayername.Text;
|
|
|
|
|
}
|
2019-01-03 11:20:16 +01:00
|
|
|
|
socketPlateauCLI sc = new socketPlateauCLI(cfg, null, new socketPlateauCLI.OnConnected(SocketCoonected));
|
2018-12-17 15:13:05 +01:00
|
|
|
|
/*sc.
|
2019-01-03 11:20:16 +01:00
|
|
|
|
sc.senCmd(new socketPlateauBase.CommandeSocket_S(socketPlateauBase.commande_E.Join, cfg));*/
|
2018-12-17 15:13:05 +01:00
|
|
|
|
}
|
2019-01-03 11:20:16 +01:00
|
|
|
|
private void SocketCoonected(object o, socketPlateauConnected e)
|
2018-12-17 15:13:05 +01:00
|
|
|
|
{
|
|
|
|
|
//################################################################################################
|
|
|
|
|
//################################################################################################
|
|
|
|
|
//################################################################################################
|
|
|
|
|
//################################################################################################
|
|
|
|
|
//################################################################################################
|
|
|
|
|
//################################################################################################
|
2019-01-03 11:20:16 +01:00
|
|
|
|
Console.WriteLine("CONNECTION ETABLEIE");
|
2019-01-04 11:28:58 +01:00
|
|
|
|
p = new Plateau(cfg.taille, cfg.PionAligner, cfg.NomJoeurBlanc, cfg.NomJoeurNoir);
|
|
|
|
|
p.Show();
|
|
|
|
|
|
2019-01-03 11:20:16 +01:00
|
|
|
|
//this.Hide();
|
2019-01-04 11:28:58 +01:00
|
|
|
|
// p.ShowDialog();
|
2019-01-03 11:20:16 +01:00
|
|
|
|
//this.Close();
|
2018-12-14 14:08:07 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|