/// <summary> /// Registers the Game Object to other clients. If this is called on the game object it will be created /// on all other connected clients. This should be called on Awake in order for OwnGameObject to work. /// </summary> public static bool RegisterNetGameObject(GameObject go, string prefabName) { if (go == null) { throw new ArgumentNullException(); } FFSystem.GetReady(); FFPrivate.FFMessageSystem.GetReady(); // object registered/created by another client, or already registered once on this client GameObjectData localGoData; int id = go.GetInstanceID(); if (singleton._GameObjecttRegistryIsLocked || singleton._localIdToGameObjectData.TryGetValue(id, out localGoData)) { return(false); } if (FFClient.isReady) { int instanceId = go.GetInstanceID(); singleton._localIdToGameObjectData.Add(instanceId, new GameObjectData(go, FFClient.clientId, -1, id)); NetObjectCreatedEvent NOCE; NOCE.pos = go.transform.position; NOCE.rot = go.transform.rotation; NOCE.scale = go.transform.localScale; NOCE.creationTime = FFClient.clientTime; NOCE.gameObjectInstanceId = instanceId; NOCE.clientOwnerNetId = FFClient.clientId; NOCE.gameObjectNetId = -1; // Set by server, -1 == Not Uninitialized // Strip (clone) int cloneBegin = prefabName.IndexOf("(Clone)"); if (cloneBegin == -1) { NOCE.prefabName = prefabName; } else { NOCE.prefabName = prefabName.Substring(0, cloneBegin); } //Debug.Log("NewObjectCreatedEvent!"); // debug FFMessageSystem.SendMessageToNet <NetObjectCreatedEvent>(NOCE, true); } else { GameObjectPreFabPair goPre; goPre.go = go; goPre.prefab = prefabName; singleton._gameObjectsToRegisterToServer.Enqueue(goPre); } return(true); }
/// <summary> /// Send to the message networked (to all other connected clients) to this board's sepecific box entry. /// </summary> public static void SendToNet(EventType message, string entry, bool varified = false) { if (activeGlobal && activeLocal) { FFMessageSystem.SendMessageToNet <EventType>(message, entry, varified); } }
/// <summary> /// Send to the message networked (to all other connected clients) to this board's sepecific box entry. /// </summary> private static void SendToNet(EventType message, string entry, bool varified = false) { Debug.Assert(false, "this codepath probably doens't work"); if (activeGlobal && activeLocal) { FFMessageSystem.SendMessageToNet <EventType>(message, entry, varified); } }
private static void SendClientSyncTimeEvent(bool isDistorsionSync) { ClientSyncTimeEvent e; e.serverLifeTime = -1; e.isDistortionSyncEvent = isDistorsionSync; e.clientSendTime = clientTimeNoDistortion; FFPacket <ClientSyncTimeEvent> packet = new FFPacket <ClientSyncTimeEvent>( FFPacketInstructionFlags.Message | FFPacketInstructionFlags.Immediate, typeof(ClientSyncTimeEvent).ToString(), e); FFMessageSystem.SendToNet <ClientSyncTimeEvent>(packet, false); }
private static void SendClientConnectedEvent(string clientName) { singleton._clientData.clientGuid = Guid.NewGuid(); ClientConnectedEvent e = new ClientConnectedEvent(); e.clientId = -1; e.serverTime = -1; e.serverStartTime = new DateTime(); e.serverName = null; e.clientName = clientName; e.clientGuid = singleton._clientData.clientGuid; e.clientSendTime = (float)FFSystem.clientWatchTime; FFMessageSystem.SendMessageToNet <ClientConnectedEvent>(e, true); }
public static void StartClient(string ipAddress, int port, string clientName) { FFClient.GetReady(); FFSystem.GetReady(); FFMessageSystem.GetReady(); if ((singleton._clientData.IsOrBeingConnected = true && singleton._clientData.clientSocketTCP != null && singleton._clientData.clientSocketTCP.socket != null && singleton._clientData.clientSocketTCP.socket.IsBound) && singleton._clientData.clientSocketUDP != null && singleton._clientData.clientSocketUDP.udpClient != null) { return; } singleton._clientData.IsOrBeingConnected = true; singleton._clientData.clientName = clientName; singleton._ipAddress = ipAddress; singleton._port = port; singleton._ipEndPoint = new IPEndPoint(IPAddress.Parse(singleton._ipAddress), singleton._port); try { // TCP singleton._clientData.clientSocketTCP = new ClientSocket(new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)); singleton._clientData.clientSocketTCP.socket.BeginConnect(singleton._ipEndPoint, new AsyncCallback(ConnectCallback), singleton._clientData); singleton._clientData.clientSocketTCP.clientData = singleton._clientData; Debug.Log("Connecting to Server..." + "\nIPEndPoint: " + singleton._ipEndPoint); } catch (Exception e) { Debug.Log("Client Failed to beging connecting to Server" + "\nException: " + e.Message); } }
/// <summary> /// Send the message networked (to all other connected clients) to other clients' go (GameObject) and everything connected. go (GameObject) must be a registered Object on other clients /// and anything connected does not need to be registered /// </summary> public static void SendToNetToAllConnected(EventType message, GameObject go, bool varifiedpacket = false) { FFMessageSystem.SendMessageToNet <EventType>(message, go.GetInstanceID(), FFPacketInstructionFlags.MessageBoardGameObjectSendToAllConnected, varifiedpacket); }
/// <summary> /// Send the message networked (to all other connected clients) to other clients' go (GameObject) and its childeren. go (GameObject) must be a registered Object on other clients /// and its childeren do not need to be registered to recieve the message /// </summary> private static void SendToNetDown(EventType message, GameObject go, bool varifiedPacket = false) { FFMessageSystem.SendMessageToNet <EventType>(message, go.GetInstanceID(), FFPacketInstructionFlags.MessageBoardGameObjectSendDown, varifiedPacket); }