/// <summary> /// Send an internal message through system. /// </summary> /// <param name="target">The steam person we are sending internal message to.</param> /// <param name="type">The type of <see cref="InternalMessage"/> we want to send.</param> internal bool SendInternal(ProductUserId target, InternalMessage type, SocketId socket) { Result sent = EpicManager.P2PInterface.SendPacket(new SendPacketOptions { AllowDelayedDelivery = true, Channel = (byte)Options.Channels.Length, Data = new[] { (byte)type }, LocalUserId = EpicManager.AccountId.ProductUserId, Reliability = PacketReliability.ReliableOrdered, RemoteUserId = target, SocketId = socket }); if (sent == Result.Success) { if (Transport.transportDebug) { DebugLogger.RegularDebugLog("[Client] - Packet sent successfully."); } } else { if (Transport.transportDebug) { DebugLogger.RegularDebugLog($"[Client] - Packet failed to send. Results: {sent}"); } } return(sent == Result.Success); }
private void OnSocketConnectToServer(SocketId socketId) { if (socketId == SocketId.Gate) { Debug.Log("Connected to gate server"); roleStatus = RoleStatus.ConnectedToGateServer; C_GetLoginServerInfo getLoginServerReq = new C_GetLoginServerInfo(); NetClientManager.instance.SendMessage <C_GetLoginServerInfo>((int)SocketId.Gate, getLoginServerReq); } else if (socketId == SocketId.Main) { Debug.Log("Connected to main server"); roleStatus = RoleStatus.ConnectedToMainServer; C_RoleLogin req = new C_RoleLogin(); req.account = ""; req.channel = 1; req.device_id = GameUtil.GetDeviceID(); req.device_info = GameUtil.GetSystemInfo(); req.login_account_id = GameUtil.GetGameLoginDeviceID(); req.platform = GameUtil.GetOS(); req.sdk_info = ""; req.token = ""; req.reserve = ""; req.device_id = "device123"; req.device_info = "xiaomi"; req.login_account_id = "device123"; req.platform = "android"; NetClientManager.instance.SendMessage <C_RoleLogin>((int)SocketId.Main, req); } }
public void ReceiveData() { try { SocketId socketId = new SocketId(); while (transport.enabled && Receive(out ProductUserId clientUserID, out socketId, out byte[] internalMessage, (byte)internal_ch)) { if (internalMessage.Length == 1) { OnReceiveInternalData((InternalMessages)internalMessage[0], clientUserID, socketId); return; // Wait one frame } else { Debug.Log("Incorrect package length on internal channel."); } } for (int chNum = 0; chNum < channels.Length; chNum++) { while (transport.enabled && Receive(out ProductUserId clientUserID, out socketId, out byte[] receiveBuffer, (byte)chNum)) { OnReceiveData(receiveBuffer, clientUserID, chNum); } } } catch (Exception e) { Debug.LogException(e); } }
public void Connect(SocketId sid, string url, int port) { Debug.Log(Time.time + " SocketMananger.Connect sid=" + sid + " url=" + url + " port=" + port); int i = (int)sid; // if (servers [i] != null) // { // if(Application.isEditor) Debug.LogError ("socket已经连接,之前没有关闭 sid=" + sid ); // Close (sid); // } if (servers[i] == null) { if (string.IsNullOrEmpty(url) || url.ToUpper() == OFFLINE) { Offline(sid); } else { var s = new CommonSocketServer(this, sid); // s.root = root; s.URL = url; s.Port = port; s.ReconnSpan = 5; if (connectedCallback != null) { s.sConnect.AddListener(connectedCallback); } servers[i] = s; s.Start(); } } }
protected Common(EosTransport transport) { channels = transport.Channels; AddNotifyPeerConnectionRequestOptions addNotifyPeerConnectionRequestOptions = new AddNotifyPeerConnectionRequestOptions(); addNotifyPeerConnectionRequestOptions.LocalUserId = EOSSDKComponent.LocalUserProductId; SocketId socketId = new SocketId(); socketId.SocketName = SOCKET_ID; addNotifyPeerConnectionRequestOptions.SocketId = socketId; OnIncomingConnectionRequest += OnNewConnection; OnRemoteConnectionClosed += OnConnectFail; EOSSDKComponent.GetP2PInterface().AddNotifyPeerConnectionRequest(addNotifyPeerConnectionRequestOptions, null, OnIncomingConnectionRequest); AddNotifyPeerConnectionClosedOptions addNotifyPeerConnectionClosedOptions = new AddNotifyPeerConnectionClosedOptions(); addNotifyPeerConnectionClosedOptions.LocalUserId = EOSSDKComponent.LocalUserProductId; addNotifyPeerConnectionClosedOptions.SocketId = socketId; EOSSDKComponent.GetP2PInterface().AddNotifyPeerConnectionClosed(addNotifyPeerConnectionClosedOptions, null, OnRemoteConnectionClosed); this.transport = transport; }
/// <summary> /// New incoming connection from someone. We check to see if its same as in address atm for security. /// </summary> /// <param name="result">The data we need to process to make a accept the new connection request.</param> protected override void OnNewConnection(OnIncomingConnectionRequestInfo result) { if (_initialWait) { return; } if (Options.ConnectionAddress == result.RemoteUserId) { EpicManager.P2PInterface.AcceptConnection( new AcceptConnectionOptions { LocalUserId = EpicManager.AccountId.ProductUserId, RemoteUserId = result.RemoteUserId, SocketId = result.SocketId }); _connectedComplete.TrySetResult(); SocketName = result.SocketId; } else { if (Logger.logEnabled) { if (Transport.transportDebug) { DebugLogger.RegularDebugLog("[Client] - P2P Acceptance Request from unknown host ID.", LogType.Error); } } } }
public void SendMessage(SocketId sid, int msgId, LuaStringBuffer msgContent) { Debug.Log("network log : C->S " + sid + " msgId=0x" + Convert.ToString(msgId, 16)); Stream stream = new MemoryStream(msgContent.buffer); socketManager.SendProtoMessage(sid, msgId, stream); }
public void ServerConnectedCallback(SocketId sid) { if (luaFunction == null) { return; } luaFunction.Call(table, sid); }
public void Connect(SocketId sid, string server) { string[] arr = server.Split(':'); string ip = arr[0]; int port = arr.Length > 1 ? (string.IsNullOrEmpty(arr[1]) ? 80 : Convert.ToInt32(arr[1])) : 80; Connect(sid, ip, port); }
public OfflineSocketServer(SocketManager sm, SocketId sid) { this.sm = sm; this.sid = sid; readpool = SimplePool <ReadData> .Instance; InitHandlers(); readdata = new List <ReadData>(); }
public void Set(SocketId other) { if (other != null) { m_ApiVersion = P2PInterface.SocketidApiLatest; SocketName = other.SocketName; } }
public CommonSocketServer(SocketManager sm, SocketId si) { this.sm = sm; this.sid = si; readpool = SimplePool <ReadData> .Instance; frametemp = new List <ReadData>(); outbuffer = new byte[65535]; }
public void Set(AddNotifyPeerConnectionRequestOptions other) { if (other != null) { m_ApiVersion = P2PInterface.AddnotifypeerconnectionrequestApiLatest; LocalUserId = other.LocalUserId; SocketId = other.SocketId; } }
public void Set(CloseConnectionsOptions other) { if (other != null) { m_ApiVersion = P2PInterface.CloseconnectionsApiLatest; LocalUserId = other.LocalUserId; SocketId = other.SocketId; } }
public void SendEmptyMessage(SocketId sid, int id) { int i = (int)sid; if (servers[i] != null) { servers[i].SendEmptyMessage(id); } }
public void Offline(SocketId sid) { var s = new OfflineSocketServer(this, sid); int i = (int)sid; // s.root = root; s.Start(); servers[i] = s; }
public void RemoveConnectCallback(SocketId socketId, Action <SocketId> callback) { Action <SocketId> hc; if (connectCallbackDict.TryGetValue(socketId, out hc)) { hc -= callback; } }
public void Set(AcceptConnectionOptions other) { if (other != null) { m_ApiVersion = P2PInterface.AcceptconnectionApiLatest; LocalUserId = other.LocalUserId; RemoteUserId = other.RemoteUserId; SocketId = other.SocketId; } }
internal void Set(OnIncomingConnectionRequestInfoInternal?other) { if (other != null) { ClientData = other.Value.ClientData; LocalUserId = other.Value.LocalUserId; RemoteUserId = other.Value.RemoteUserId; SocketId = other.Value.SocketId; } }
/// <summary> /// /// </summary> /// <param name="clientUserID"></param> /// <param name="socket"></param> protected void CloseP2PSessionWithUser(ProductUserId clientUserID, SocketId socket) { EpicManager.P2PInterface.CloseConnection( new CloseConnectionOptions { LocalUserId = EpicManager.AccountId.ProductUserId, RemoteUserId = clientUserID, SocketId = socket }); }
protected void Send(ProductUserId host, SocketId socketId, byte[] msgBuffer, byte channel) => EOSSDKComponent.GetP2PInterface().SendPacket(new SendPacketOptions() { AllowDelayedDelivery = true, Channel = channel, Data = msgBuffer, LocalUserId = EOSSDKComponent.LocalUserProductId, Reliability = channels[channel], RemoteUserId = host, SocketId = socketId });
public void AddLuaReconnectCallback(SocketId ssid, LuaFunction callback) { int idx = (int)ssid; if (servers[idx] != null) { var s = servers[idx] as CommonSocketServer; s.sReconnect.AddListener((SocketId sid) => { callback.Call((int)sid); }); } }
public void Reconnect(SocketId sid) { int i = (int)sid; if (servers[i] != null) { if (servers[i] is CommonSocketServer) { var s = servers[i] as CommonSocketServer; s.Reconnect(); } } }
public string GetSocketIPById() { if (SocketId == null) { return(string.Empty); } string[] array = SocketId.Split(':'); if (array.Length != 2) { return(string.Empty); } return(array[0]); }
public void Stop(SocketId sid) { int i = (int)sid; if (servers[i] != null) { if (servers[i] is CommonSocketServer) { CommonSocketServer s = servers[i] as CommonSocketServer; s.Stop(); } } }
protected void SendInternal(ProductUserId target, SocketId socketId, InternalMessages type) { EOSSDKComponent.GetP2PInterface().SendPacket(new SendPacketOptions() { AllowDelayedDelivery = true, Channel = (byte)internal_ch, Data = new byte[] { (byte)type }, LocalUserId = EOSSDKComponent.LocalUserProductId, Reliability = PacketReliability.ReliableOrdered, RemoteUserId = target, SocketId = socketId }); }
public void AddReconnectCallback(SocketId socketId, Action <SocketId, int> callback) { Action <SocketId, int> hc; if (!reconnectCallbackDict.TryGetValue(socketId, out hc)) { hc = callback; reconnectCallbackDict[socketId] = hc; } else { hc += callback; } }
public void AddDisconnectCallback(SocketId socketId, Action <SocketId> callback) { Action <SocketId> hc; if (!disconnectCallbackDict.TryGetValue(socketId, out hc)) { hc = callback; disconnectCallbackDict[socketId] = hc; } else { hc += callback; } }
public void SendMessage <T>(SocketId socketId, T m) { string s = typeof(T).FullName; int t; bool b = cdict.TryGetValue(s, out t); if (b) { Stream str = new MemoryStream(); Serializer.Serialize <T>(str, m); string tname = typeof(T).Name; socketManager.SendProtoMessage(socketId, t, str); HDebugger.Log(HDebuggerModule.Proto, "SendMessage network log : C --> S : " + s); } }
public void SendProtoMessage(SocketId sid, int id, Stream stream) { int i = (int)sid; //byte[] bytes = new byte[stream.Length]; //stream.Read(bytes, 0, bytes.Length); //string StringOut = ""; //foreach (byte InByte in bytes) //{ // StringOut = StringOut + String.Format("{0:X2} ", InByte); //} //Debug.Log("========: " + StringOut); if (servers[i] != null) { servers[i].SendProtoMessage(id, stream); } }