Skip to content

Commit

Permalink
Merge pull request #5 from Sky-CSC/InGame
Browse files Browse the repository at this point in the history
For the deployment of version 1.0.0
  • Loading branch information
Sky-CSC authored Mar 21, 2023
2 parents b0ff477 + 91bbcf0 commit b2f55e1
Show file tree
Hide file tree
Showing 405 changed files with 166,847 additions and 23,398 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,4 @@ RaceManagerOld/**
Releases/**
RaceManager/index/data.json
RaceManager/lcsc.pfx
OSL-Server/Configuration/webApiRiot.json
3 changes: 3 additions & 0 deletions OSL-Client/CloseEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

namespace OSL_Client
{
/// <summary>
///
/// </summary>
internal class CloseEvent
{
[DllImport("Kernel32")]
Expand Down
206 changes: 168 additions & 38 deletions OSL-Client/Communication/OSLServer/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public partial class AsyncClient

// The port number for the remote device.
//private const int port = 11000;
public static Socket oslServerSocket = null;

// ManualResetEvent instances signal completion.
private static ManualResetEvent connectDone =
Expand All @@ -47,67 +48,196 @@ public partial class AsyncClient
// The response from the remote device.
private static String response = String.Empty;



/// <summary>
/// Run connexion for connect to server
///
/// </summary>
/// <param name="data">data recive</param>
/// <returns>Connexion are enabled</returns>
/// <param name="data"></param>
/// <returns></returns>
public static bool StartClient(String data)
{
// Connect to a remote device.
try
{
// Establish the remote endpoint for the socket.
// The name of the
// remote device is "host.contoso.com".
IPHostEntry ipHostInfo = Dns.Resolve(Config.serverIPSocketOSLServer);
IPAddress ipAddress = ipHostInfo.AddressList[0];
foreach (IPAddress address in ipHostInfo.AddressList){
if (address.AddressFamily.ToString() == ProtocolFamily.InterNetworkV6.ToString())
{
Socket client = null;
IPEndPoint ipe = null;

}
else if (address.AddressFamily.ToString() == ProtocolFamily.InterNetwork.ToString())
IPHostEntry hostEntry = Dns.GetHostEntry(Config.serverIPSocketOSLServer);

foreach (IPAddress address in hostEntry.AddressList)
{
Console.WriteLine(address);
if (address.AddressFamily.ToString() == ProtocolFamily.InterNetwork.ToString())
{
ipAddress = address;
ipe = new IPEndPoint(address, Config.serverPortSocketOSLServer);
Socket tempSocket =
new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
try
{
tempSocket.Connect(ipe);

if (tempSocket.Connected)
{
client = tempSocket;
_logger.log(LoggingLevel.INFO, "StartClient()", "Socket connected");
break;
}
else
{
continue;
}
}
catch (Exception e)
{
_logger.log(LoggingLevel.ERROR, "StartClient()", "Error tempSocket.Connect(ipe) : " + e.Message);
}
}
}

_logger.log(LoggingLevel.INFO, "StartClient()", "ipAddress : " + ipAddress);

IPEndPoint remoteEP = new IPEndPoint(ipAddress, Config.serverPortSocketOSLServer);

// Create a TCP/IP socket.
Socket client = new Socket(ipAddress.AddressFamily,
SocketType.Stream, ProtocolType.Tcp);

// Connect to the remote endpoint.
client.BeginConnect(remoteEP,
new AsyncCallback(ConnectCallback), client);
//Console.WriteLine(client.Connected);
connectDone.WaitOne();

//_logger.log(LoggingLevel.INFO, "StartClient()", "Data : " + data);
Send(client, data);
//Send(client, "This is a test<EOF>");
sendDone.WaitOne();

// Receive the response from the remote device.
Receive(client);
receiveDone.WaitOne();
//Receive(client);
//receiveDone.WaitOne();

_logger.log(LoggingLevel.INFO, "StartClient()", "Response received : " + response);
oslServerSocket = client;

// Release the socket.
client.Shutdown(SocketShutdown.Both);
client.Close();
return true;
}
catch (Exception e)
{
_logger.log(LoggingLevel.ERROR, "StartClient()", "Error Client : " + e.Message);
return false;
}
return true;
}

/// <summary>
///
/// </summary>
/// <returns></returns>
public static bool CloseClient()
{
try
{
oslServerSocket.Shutdown(SocketShutdown.Both);
oslServerSocket.Close();
return true;
}
catch (Exception e)
{
_logger.log(LoggingLevel.ERROR, "CloseClient()", "Error Client : " + e.Message);
return false;
}
}
}















/// <summary>
/// Run connexion for connect to server
/// </summary>
/// <param name="data">data recive</param>
/// <returns>Connexion are enabled</returns>
//public static bool StartClient(String data)
//{
// // Connect to a remote device.
// try
// {
// // Establish the remote endpoint for the socket.
// // The name of the
// // remote device is "host.contoso.com".
// //IPHostEntry ipHostInfo = Dns.Resolve(Config.serverIPSocketOSLServer);
// //IPAddress ipAddress = ipHostInfo.AddressList[0];
// //foreach (IPAddress address in ipHostInfo.AddressList){
// // Console.WriteLine(address);
// // if (address.AddressFamily.ToString() == ProtocolFamily.InterNetworkV6.ToString())
// // {

// // }
// // else if (address.AddressFamily.ToString() == ProtocolFamily.InterNetwork.ToString())
// // {
// // ipAddress = address;
// // }
// //}

// Socket client = null;
// IPEndPoint ipe = null;

// IPHostEntry hostEntry = Dns.GetHostEntry(Config.serverIPSocketOSLServer);

// foreach (IPAddress address in hostEntry.AddressList)
// {
// Console.WriteLine(address);
// ipe = new IPEndPoint(address, Config.serverPortSocketOSLServer);
// Socket tempSocket =
// new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
// try
// {
// tempSocket.Connect(ipe);

// if (tempSocket.Connected)
// {
// client = new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
// break;
// }
// else
// {
// continue;
// }
// }
// catch (Exception e)
// {
// _logger.log(LoggingLevel.ERROR, "StartClient()", "Error tempSocket.Connect(ipe) : " + e.Message);
// }
// }

// //_logger.log(LoggingLevel.INFO, "StartClient()", "ipAddress : " + ipAddress);

// //IPEndPoint remoteEP = new IPEndPoint(ipAddress, Config.serverPortSocketOSLServer);

// // Create a TCP/IP socket.
// //client = new Socket(ipAddress.AddressFamily,
// // SocketType.Stream, ProtocolType.Tcp);

// // Connect to the remote endpoint.
// client.BeginConnect(ipe, new AsyncCallback(ConnectCallback), client);
// //Console.WriteLine(client.Connected);
// connectDone.WaitOne();

// //_logger.log(LoggingLevel.INFO, "StartClient()", "Data : " + data);
// Send(client, data);
// //Send(client, "This is a test<EOF>");
// sendDone.WaitOne();

// // Receive the response from the remote device.
// Receive(client);
// receiveDone.WaitOne();

// _logger.log(LoggingLevel.INFO, "StartClient()", "Response received : " + response);

// // Release the socket.
// //client.Shutdown(SocketShutdown.Both);
// //client.Close();
// }
// catch (Exception e)
// {
// _logger.log(LoggingLevel.ERROR, "StartClient()", "Error Client : " + e.Message);
// return false;
// }
// return true;
//}
//}
}
20 changes: 19 additions & 1 deletion OSL-Client/Communication/OSLServer/Recive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public partial class AsyncClient
/// Receive
/// </summary>
/// <param name="client">Socket client</param>
private static void Receive(Socket client)
public static void Receive(Socket client)
{
try
{
Expand All @@ -34,6 +34,24 @@ private static void Receive(Socket client)
}
}

public static void Receive()
{
try
{
// Create the state object.
StateObject state = new StateObject();
state.workSocket = oslServerSocket;

// Begin receiving the data from the remote device.
oslServerSocket.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
new AsyncCallback(ReceiveCallback), state);
}
catch (Exception e)
{
_logger.log(LoggingLevel.ERROR, "Receive()", "Error Client Recive : " + e.Message);
}
}

/// <summary>
/// ReceiveCallback
/// </summary>
Expand Down
12 changes: 11 additions & 1 deletion OSL-Client/Communication/OSLServer/Send.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public partial class AsyncClient
/// </summary>
/// <param name="client">Socket client</param>
/// <param name="data">data to send</param>
private static void Send(Socket client, String data)
public static void Send(Socket client, String data)
{
// Convert the string data to byte data using ASCII encoding.
byte[] byteData = Encoding.UTF8.GetBytes(data);
Expand All @@ -27,6 +27,16 @@ private static void Send(Socket client, String data)
new AsyncCallback(SendCallback), client);
}

public static void Send(String data)
{
// Convert the string data to byte data using ASCII encoding.
byte[] byteData = Encoding.UTF8.GetBytes(data);

// Begin sending the data to the remote device.
oslServerSocket.BeginSend(byteData, 0, byteData.Length, 0,
new AsyncCallback(SendCallback), oslServerSocket);
}

/// <summary>
/// SendCallback
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion OSL-Client/Configuration/configServerSocketOSLServer.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"ipOSLServer": "localhost",
"ipOSLServer": "192.168.1.5",
"portOSLServer": 45678
}
6 changes: 3 additions & 3 deletions OSL-Client/OSL-Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<ApplicationIcon>Icone_Terre.ico</ApplicationIcon>
<Copyright>Sky-csc</Copyright>
<PackageProjectUrl>https://github.com/Sky-CSC/OSL</PackageProjectUrl>
<AssemblyVersion>0.1.0</AssemblyVersion>
<FileVersion>0.1.0</FileVersion>
<Version>0.1.0-alpha</Version>
<AssemblyVersion>1.0.0</AssemblyVersion>
<FileVersion>1.0.0</FileVersion>
<Version>1.0.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
8 changes: 6 additions & 2 deletions OSL-Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
//using OSL_Client.RiotApp.MemoryProcessing;
using OSL_Client.Communication.OSLServer;
using System.Net;
using OSL_Client.RiotApp.MemoryProcessing;

Console.WriteLine("");
OSLLogger logger = new("Program");
Expand All @@ -21,7 +22,7 @@
Console.WriteLine("###########################################\n");
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("###########################");
Console.WriteLine("##### Version 0.1.0 #####");
Console.WriteLine("###### Version 1.0.0 ######");
Console.WriteLine("###########################\n");
Console.ResetColor();

Expand All @@ -30,6 +31,7 @@

String data = "Hello OSL-Server is OSL-Client managed by Sky";
AsyncClient.StartClient(data);
Thread.Sleep(1000);
//while (!AsyncClient.StartClient(data))
//{

Expand All @@ -55,4 +57,6 @@
}
}
}
}
}

//TestClass.Test();
Loading

0 comments on commit b2f55e1

Please sign in to comment.