protected override void AttributeSetup(GameObject rootObj, string name, bool serverside, bool clientside, bool bundling) { base.AttributeSetup(rootObj, name, serverside, clientside, bundling); isBuildingPrivilege = rootObj.GetComponent <BuildingPrivlidge>(); bounds = rootObj.GetComponent <BaseEntity>().bounds; deployable = GetComponent <Deployable>(); placeholder = GetComponentInChildren <ConstructionPlaceholder>(); allSockets = GetComponentsInChildren <Socket_Base>(true); allProximities = GetComponentsInChildren <BuildingProximity>(true); socketHandle = GetComponentsInChildren <SocketHandle>(true).FirstOrDefault(); ConstructionGrade[] components = rootObj.GetComponents <ConstructionGrade>(); grades = new ConstructionGrade[5]; ConstructionGrade[] array = components; foreach (ConstructionGrade constructionGrade in array) { constructionGrade.construction = this; grades[(int)constructionGrade.gradeBase.type] = constructionGrade; } for (int j = 0; j < grades.Length; j++) { if (!(grades[j] == null)) { defaultGrade = grades[j]; break; } } }
//--Socket消息-- private void OnSocket(int key, byte[] buffer) { if (handleList.ContainsKey(key)) { SocketHandle handle = handleList[key]; if (handle != null) { if (buffer != null) { MemoryStream stream = new MemoryStream(); //可以用对象池 stream.Write(buffer, 0, buffer.Length); stream.Position = 0; handle(stream); stream.Dispose(); } else { // string str = "协议收到处理:" + key.ToString("X"); // Singleton<ModuleEventDispatcher>.GetInstance().dispatchDebugLogEvent(str); // Debuger.Log(str); handle(null); } } } else { Singleton <ModuleEventDispatcher> .GetInstance().DispatchDebugLogEvent("协议未处理:" + key.ToString("X")); } }
/// <summary> /// socket的一系列操作的回调 /// </summary> /// <param name="handle"></param> private void DoHandleEvent(SocketHandle handle) { string handleName = handle.Name; switch (handleName) { case "HandleSendMsgComplete": OnSendCompleteCallback(); break; case "HandleConnectSuccess": OnConnectSuccessCallback(); break; //socket检测的未连接成功弃用。连接socket计时时间内未连接上,视为未连接成功 case "HandleConnectFailed": OnConnectFailedCallback(); break; case "HandleSocketClose": OnCloseCallback(); break; default: LogUtil.LogWarning(string.Format("没有{0}对应的方法", handleName)); break; } }
protected override void AttributeSetup(GameObject rootObj, string name, bool serverside, bool clientside, bool bundling) { base.AttributeSetup(rootObj, name, serverside, clientside, bundling); this.isBuildingPrivilege = rootObj.GetComponent <BuildingPrivlidge>(); this.bounds = rootObj.GetComponent <BaseEntity>().bounds; this.deployable = base.GetComponent <Deployable>(); this.placeholder = base.GetComponentInChildren <ConstructionPlaceholder>(); this.allSockets = base.GetComponentsInChildren <Socket_Base>(true); this.allProximities = base.GetComponentsInChildren <BuildingProximity>(true); this.socketHandle = base.GetComponentsInChildren <SocketHandle>(true).FirstOrDefault <SocketHandle>(); ConstructionGrade[] components = rootObj.GetComponents <ConstructionGrade>(); this.grades = new ConstructionGrade[5]; ConstructionGrade[] constructionGradeArray = components; for (int i = 0; i < (int)constructionGradeArray.Length; i++) { ConstructionGrade constructionGrade = constructionGradeArray[i]; constructionGrade.construction = this; this.grades[(int)constructionGrade.gradeBase.type] = constructionGrade; } for (int j = 0; j < (int)this.grades.Length; j++) { if (this.grades[j] != null) { this.defaultGrade = this.grades[j]; return; } } }
public ConnectionDrawData(int id, SocketHandle port1, SocketHandle port2, UILineRenderer lineRenderer) { this.id = id; this.output = port1; this.input = port2; this.lineRenderer = lineRenderer; }
protected override void AttributeSetup( GameObject rootObj, string name, bool serverside, bool clientside, bool bundling) { base.AttributeSetup(rootObj, name, serverside, clientside, bundling); this.isBuildingPrivilege = Object.op_Implicit((Object)rootObj.GetComponent <BuildingPrivlidge>()); this.bounds = ((BaseEntity)rootObj.GetComponent <BaseEntity>()).bounds; this.deployable = (Deployable)((Component)this).GetComponent <Deployable>(); this.placeholder = (ConstructionPlaceholder)((Component)this).GetComponentInChildren <ConstructionPlaceholder>(); this.allSockets = (Socket_Base[])((Component)this).GetComponentsInChildren <Socket_Base>(true); this.allProximities = (BuildingProximity[])((Component)this).GetComponentsInChildren <BuildingProximity>(true); this.socketHandle = ((IEnumerable <SocketHandle>)((Component)this).GetComponentsInChildren <SocketHandle>(true)).FirstOrDefault <SocketHandle>(); M0[] components = rootObj.GetComponents <ConstructionGrade>(); this.grades = new ConstructionGrade[5]; foreach (ConstructionGrade constructionGrade in (ConstructionGrade[])components) { constructionGrade.construction = this; this.grades[(int)constructionGrade.gradeBase.type] = constructionGrade; } for (int index = 0; index < this.grades.Length; ++index) { if (!((PrefabAttribute)this.grades[index] == (PrefabAttribute)null)) { this.defaultGrade = this.grades[index]; break; } } }
private void SendCallBack(IAsyncResult ar) { SocketHandle sendHandle = (SocketHandle)ar.AsyncState; sendHandle.socket.EndSend(ar); if (sendSucceed != null) { sendSucceed(sendHandle.msg); } }
public void AddHandle(int msgId, SocketHandle handle) { if (handleList.ContainsKey(msgId)) { Debuger.LogError("重复添加协议处理:" + msgId); Singleton <ModuleEventDispatcher> .GetInstance().DispatchDebugLogEvent("重复添加协议处理:" + msgId); return; } handleList[msgId] = handle; }
protected override bool ReleaseHandle() { if (NetEventSource.IsEnabled) { NetEventSource.Info(this); } FreeNativeOverlapped(); #if DEBUG SocketHandle.Release(); #endif return(true); }
protected override bool ReleaseHandle() { if (GlobalLog.IsEnabled) { GlobalLog.Print("SafeNativeOverlapped#" + LoggingHash.HashString(this) + "::ReleaseHandle()"); } FreeNativeOverlapped(); #if DEBUG SocketHandle.Release(); #endif return(true); }
public void Close() { if (Connected) { if (OSUtils.IsWindows) { NativeMethods.closesocket(SocketHandle); } else { NativeMethods.close_libc(SocketHandle.ToInt32()); } SocketHandle = IntPtr.Zero; } }
// drawing private void DrawConnection(SocketHandle port1, SocketHandle port2, UILineRenderer lineRenderer) { var pointList = new List <Vector2>(); for (float i = 0; i < vertexCount; i++) { var t = i / vertexCount; pointList.Add(Utility.CubicCurve(GetLocalPoint(port1.handle1.position), GetLocalPoint(port1.handle2.position), GetLocalPoint(port2.handle1.position), GetLocalPoint(port2.handle2.position), t)); } lineRenderer.m_points = pointList.ToArray(); lineRenderer.SetVerticesDirty(); }
private static void DrawDragging(SocketHandle port) { Vector2 localPointerPos; RectTransformUtility.ScreenPointToLocalPointInRectangle(_lineContainer, Input.mousePosition, null, out localPointerPos); _pointerLocator.localPosition = localPointerPos; var pointList = new List <Vector2>(); for (float i = 0; i < 120; i++) { var t = i / 120; pointList.Add(Utility.QuadraticCurve(GetLocalPoint(port.handle1.position), GetLocalPoint(port.handle2.position), GetLocalPoint(_pointerLocator.position), t)); } _lineRenderer.m_points = pointList.ToArray(); _lineRenderer.SetVerticesDirty(); }
public void SendMsg(string msg) { if (clientSocket.Connected) { try { if (socketHandle == null) { socketHandle = new SocketHandle(clientSocket); socketHandle.msg = msg; } NetBufferWriter netBufferWriter = new NetBufferWriter(); byte[] sendBuffer = netBufferWriter.GetByte(msg); clientSocket.BeginSend(sendBuffer, 0, sendBuffer.Length, SocketFlags.None, SendCallBack, socketHandle); } catch (Exception e) { Debug.Log(e.Message); } } }
public override void Call() { unchecked { unsafe { ws2_32.WSAData wsaData = new ws2_32.WSAData(); wsaData.Version = 2; wsaData.HighVersion = 2; if (ws2_32.WSAStartup(36, out wsaData) == 0) //0=success { IntPtr SocketHandle; void * SocketAddr; SocketHandle = ws2_32.socket(ws2_32.AddressFamily.InterNetworkv4, ws2_32.SocketType.Stream, ws2_32.ProtocolType.Tcp); SocketAddr = (void *)SocketHandle; if (SocketHandle != (IntPtr)ws2_32.INVALID_SOCKET) { ws2_32.sockaddr_in remoteAddress = new ws2_32.sockaddr_in(); remoteAddress.sin_family = 2; remoteAddress.sin_port = ws2_32.htons(Convert.ToUInt16(args[1].value)); remoteAddress.sin_addr = (int)ws2_32.inet_addr((string)args[0].value); if (ws2_32.bind(SocketHandle, remoteAddress, Marshal.SizeOf(remoteAddress)) == 0) { if (ws2_32.listen(SocketHandle, 0) == 0) { AssemblerExecute.registers.EAX = SocketHandle.ToInt32(); } } } } } } }
public ClientManager(Client client) { this.client = client; this.socketHandle = new SocketHandle(this.client); }
public void Add(int connId, SocketHandle from, SocketHandle target) { _connections.Add(connId, new ConnectionDrawData(connId, from, target, CreateLine())); }