//using System; //using System.Collections.Generic; //using System.Linq; //using System.Text; //using System.Net.Sockets; //using Holo.Virtual.Users; //using Holo.Socketservers; //using Holo.GameConnectionSystem; //namespace Holo.Source.GameConnectionSystem //{ // public class gameConnection // { // #region Declares // private Socket ClientSocket; // private byte[] dataBuffer; // private int _ConnectionID; // private virtualUser ConnectedUser; // #endregion // #region Constructor // public gameConnection(Socket _ClientSocket, int _ConnectionID) // { // this.ConnectedUser = new virtualUser(this); // this.ClientSocket = _ClientSocket; // this._ConnectionID = _ConnectionID; // this.dataBuffer = new byte[1024]; // this.ClientSocket.BeginReceive(this.dataBuffer, 0, this.dataBuffer.Length, SocketFlags.None, new AsyncCallback(this.dataArrival), null); // PreformStatusCheck(); // } // #endregion // #region Properities // internal string connectionRemoteIP // { // get // { // return ClientSocket.RemoteEndPoint.ToString().Split(':')[0]; // } // } // #endregion // #region Methods // internal void PreformStatusCheck() // { // if (this.ClientSocket.Connected == false) // { // Close(); // //Out.WriteLine("Connection" + _ConnectionID + " is dead"); // } // else // { // ConnectedUser.pingOK = true; // sendData("@@"); // //Out.WriteLine("Connection" + _ConnectionID + " is ready for connections"); // } // } // internal void dataArrival(IAsyncResult iAr) // { // try // { // int bytesReceived = new int(); // try // { // bytesReceived = ClientSocket.EndReceive(iAr); // } // catch // { // Close(); // return; // } // string connectionData = System.Text.Encoding.Default.GetString(dataBuffer, 0, bytesReceived); // if (connectionData == "" || connectionData.Contains("\x01") || connectionData.Contains("\x02") || connectionData.Contains("\x05") || connectionData.Contains("\x09")) // { // Close(); // return; // } // while (connectionData != "") // { // int v = Encoding.decodeB64(connectionData.Substring(1, 2)); // string proccesspacket = connectionData.Substring(3, v); // ConnectedUser.processPacket(proccesspacket); // connectionData = connectionData.Substring(v + 3); // } // } // catch (Exception e) { Out.WriteDCError(e.ToString()); Close(); } // finally // { // if (ClientSocket.Connected == true) // ClientSocket.BeginReceive(dataBuffer, 0, dataBuffer.Length, SocketFlags.None, new AsyncCallback(dataArrival), ClientSocket); // } // } // internal void Close() // { // try // { // ClientSocket.Shutdown(SocketShutdown.Both); // ClientSocket.Close(); // gameSocketServer.freeConnection(_ConnectionID); // ConnectedUser.Reset(); // } // catch { } // } // internal void sendData(string Data) // { // try // { // byte[] dataBytes = System.Text.Encoding.Default.GetBytes(Data + Convert.ToChar(1)); // ClientSocket.BeginSend(dataBytes, 0, dataBytes.Length, 0, new AsyncCallback(sentData), ClientSocket); // } // catch // { // Close(); // } // } // internal void sentData(IAsyncResult iAr) // { // try { ClientSocket.EndSend(iAr); } // catch { Close(); } // } // internal int ConnectionID // { // get // { // return this._ConnectionID; // } // } // #endregion // } //}