public void Connect(IPAddress ip, int port) { DebugLog.Debug($"TcpClientSocket::Connect->Connecting to {ip}:{port}..."); socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.BeginConnect(ip, port, OnConnected, socket); }
internal void DoUpdate(float deltaTime) { //检查Loader初始化状态 if (State == AssetLoaderState.Initing) { DoInitUpdate(); if (State == AssetLoaderState.Running) { DebugLog.Debug(AssetConst.LOGGER_NAME, "AssetLoader::DoUpdate->Loader init success."); initCallback?.Invoke(true); } else if (State == AssetLoaderState.Error) { DebugLog.Error(AssetConst.LOGGER_NAME, "AssetLoader::DoUpdate->Loader init failed."); initCallback?.Invoke(false); } return; } else if (State != AssetLoaderState.Running) { return; } DoWaitingDataUpdate(); DoAsyncOperationUpdate(); DoLoadingDataUpdate(); DoUnloadUnsedAssetUpdate(); }
private void DoWaitingDataUpdate() { while (dataWaitingQueue.Count > 0 && operations.Count < MaxLoadingCount) { AssetLoaderData data = dataWaitingQueue.Dequeue(); StartLoadingData(data); data.State = AssetLoaderDataState.Loading; dataLoadingList.Add(data); DebugLog.Debug(AssetConst.LOGGER_NAME, $"AssetLoader::DoWaitingDataUpdate->Start Load Data.data = {data}"); } }
void OnDisconnected(IAsyncResult ar) { var socket = (Socket)ar.AsyncState; socket.EndDisconnect(ar); socket.Close(); base.socket = null; DebugLog.Debug("TcpClientSocket::OnDisconnected->Disconnected."); TriggerOnDisconnect(); }
public override void Disconnect() { if (IsConnected) { DebugLog.Debug("TcpClientSocket::Disconnect->Disconnecting..."); IsConnected = false; socket.BeginDisconnect(false, OnDisconnected, socket); } else { DebugLog.Info("TcpClientSocket::Disconnect->Already disconnected."); } }
/// <summary> /// 按批量方式进行资源的加载 /// 如果指定使用标签进行资源加载,则会忽略<paramref name="addresses"/>的值 /// </summary> /// <param name="label">加载设定指定标签的资源</param> /// <param name="addresses">资源加载地址</param> /// <param name="isInstance">是否需要实例化</param> /// <param name="complete">单个资源加载完毕后回调</param> /// <param name="batchComplete">所有资源加载完毕后回调</param> /// <param name="progress">单个资源加载进度回调</param> /// <param name="batchProgress">所有资源加载进度回调</param> /// <param name="priority">优先级</param> /// <param name="userData">自定义参数</param> /// <returns></returns> internal AssetHandler LoadBatchAssetAsync( string label, string[] addresses, bool isInstance, OnAssetLoadComplete complete, OnBatchAssetLoadComplete batchComplete, OnAssetLoadProgress progress, OnBatchAssetsLoadProgress batchProgress, AssetLoaderPriority priority, SystemObject userData) { //如果指定按标签加载资源,则查找标记为指定标签的所有资源 if (!string.IsNullOrEmpty(label)) { addresses = addressConfig.GetAddressesByLabel(label); DebugLog.Debug(AssetConst.LOGGER_NAME, $"AssetLoader::LoadBatchAssetAsync->Load asset by label.label = {label},addresses = {string.Join(",",addresses)}"); } if (addresses == null || addresses.Length == 0) { DebugLog.Error(AssetConst.LOGGER_NAME, "AAssetLoader::LoadBatchAssetAsync->addresses is null"); return(null); } //获取资源真实的路径 string[] paths = addressConfig.GetPathsByAddresses(addresses); if (paths == null || paths.Length == 0) { DebugLog.Error(AssetConst.LOGGER_NAME, "AssetLoader::LoadBatchAssetAsync->paths is null"); return(null); } else { DebugLog.Debug(AssetConst.LOGGER_NAME, $"AssetLoader::LoadBatchAssetAsync->find assetPath by address.addresses = {string.Join(",", addresses)},path = {string.Join(",",paths)}"); } if (dataWaitingQueue.Count >= dataWaitingQueue.MaxSize) { dataWaitingQueue.Resize(dataWaitingQueue.MaxSize * 2); DebugLog.Debug(AssetConst.LOGGER_NAME, "AssetLoader::LoadBatchAssetAsync->Reset the queue size."); } AssetLoaderData data = dataPool.Get(); data.InitData(label, addresses, paths, isInstance, complete, progress, batchComplete, batchProgress, userData); data.State = AssetLoaderDataState.Waiting; dataWaitingQueue.Enqueue(data, (float)priority); return(data.Handler); }
public void Listen(int port, int backlog = 100) { socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); try { socket.Bind(new IPEndPoint(IPAddress.Any, port)); socket.Listen(backlog); IsConnected = true; DebugLog.Debug($"TcpServerSocket::Listen->Listening on port {port}..."); Accept(); } catch (Exception ex) { socket = null; DebugLog.Warning(ex.Message); } }
void OnConnected(IAsyncResult ar) { var socket = (Socket)ar.AsyncState; try { socket.EndConnect(ar); IsConnected = true; DebugLog.Debug("TcpClientSocket::Connect->Connected"); OnConnect?.Invoke(this, null); StartReceiving(socket); } catch (Exception ex) { DebugLog.Warning($"TcpClientSocket::Connect->{ex.Message}"); TriggerOnDisconnect(); } }
protected void OnReceived(IAsyncResult ar) { var receiveVO = (ReceiveVO)ar.AsyncState; if (IsConnected) { var bytesReceived = receiveVO.socket.EndReceive(ar); if (bytesReceived == 0) { DebugLog.Info("AbstractTcpSocket::OnReceived->the length of bytes which was received from net is zero.the net was closed by remote"); DisconnectedByRemote(receiveVO.socket); } else { DebugLog.Debug($"AbstractTcpSocket::OnReceived->Received {bytesReceived} bytes."); TriggerOnReceive(receiveVO, bytesReceived); Receive(receiveVO); } } }
public static unsafe LaunchStatus Launch(int id, string hostAddress, int port, string clientPath, string razorPath, bool useRazor, bool removeEncryption, string serverDirectory, string[] patchfiles) { _log.Debug("Launching Server [ host: {0} port: {1} client: {2} razor: {3} useRazor: {4} removeEncryption: {5} serverDirectory: {6} patchCount: {7} ]", hostAddress, port, clientPath, razorPath, useRazor, removeEncryption, serverDirectory, patchfiles == null ? 0 : patchfiles.Length); UInt32 pid; LaunchStatus err; string encPath = Path.Combine(Directory.GetCurrentDirectory(), "EncPatcher.dll"); string overrideFile = BuildOverrideList(hostAddress, port, serverDirectory, patchfiles); if (!File.Exists(clientPath)) { throw new FileNotFoundException(clientPath); } byte[] param = new byte[257]; MemoryStream memStream = new MemoryStream(param); BinaryWriter writer = new BinaryWriter(memStream); if (useRazor && !string.IsNullOrEmpty(razorPath) && File.Exists(razorPath)) { writer.Write((byte)0); // when razor is enabled it will remove the encryption for us } else { writer.Write((byte)Convert.ToByte(removeEncryption)); } writer.Write(overrideFile.ToCharArray()); writer.Close(); fixed(byte *para_ptr = param) { err = (LaunchStatus)Load(clientPath, encPath, "Attach", para_ptr, param.Length, out pid); } if (err == LaunchStatus.SUCCESS) { _log.Debug("Client launch successful."); if (pid != 0) { Program.Database.LogProcess(id, pid); if (Program.Database.MinimizeOnPlay && Program.MainForm != null) { Program.MainForm.WindowState = System.Windows.Forms.FormWindowState.Minimized; } if (!string.IsNullOrEmpty(razorPath) && useRazor) { string opts; if (removeEncryption) { opts = "--clientenc"; } else { opts = "--clientenc --serverenc"; } _log.Debug("Attaching Razor [pid={0}] [args={1}]", pid, opts); System.Diagnostics.Process.Start(razorPath, String.Format("{0} --pid {1}", opts, pid)); } } } return(err); }