// Update is called once per frame void Update() { if (!Channel.GetNetwork().IsClient()) { DateTime now = new DateTime(); now = DateTime.Now; TimeSpan duration = now - last_clientupdate; if (duration > TimeSpan.FromMilliseconds(100)) { float time = Time.time; last_clientupdate = now; network_data.move_player m = new network_data.move_player(); IDictionaryEnumerator i = Channel.FirstEntity(); while (i.MoveNext()) { GameObject g = (GameObject)i.Value; m.set((int)i.Key, Channel.GetChannel()); m.position = ((GameObject)i.Value).transform.localPosition; m.velocity = ((GameObject)i.Value).GetComponent <ship>().GetVelocity(); m.rotation = ((GameObject)i.Value).transform.localRotation; m.time = time; byte[] data1 = network_utils.nData.Instance.SerializeMsg <network_data.move_player>(m); foreach (KeyValuePair <int, GameObject> gg in ShipList) { gg.Value.GetComponent <channel>().SendToChannel(ref data1); } } } } ServerTime.Update(Time.deltaTime); }
// Update is called once per frame void Update() { if (!Channel || !Channel.GetNetwork()) { return; } if (!Channel.GetNetwork().IsClient()) { InterpolateMovement(puppet.trans_flag_rotation); transform.localPosition += myrigidbody.gameObject.transform.localPosition; myrigidbody.gameObject.transform.localPosition = Vector3.zero; // transform.localRotation *= myrigidbody.gameObject.transform.localRotation; // myrigidbody.gameObject.transform.localRotation = Quaternion.Euler(0, 0, 0); } else { if (!IsCockpitUsedByMe()) { InterpolateMovement(puppet.trans_flag_position | puppet.trans_flag_rotation); } else { InterpolateMovement(puppet.trans_flag_position); transform.localRotation *= myrigidbody.gameObject.transform.localRotation; myrigidbody.gameObject.transform.localRotation = Quaternion.Euler(0, 0, 0); } } DateTime now = new DateTime(); now = DateTime.Now; TimeSpan duration = now - last_clientupdate; if (Channel.GetNetwork().IsClient()) { int id = Channel.GetNetwork().GetComponent <client>().ingameContID; GameObject g = Channel.GetEntity(id); if (duration > TimeSpan.FromMilliseconds(100) && g != null) { float time = Time.time; last_clientupdate = now; network_data.move_player m = new network_data.move_player(); m.set(id, Channel.GetChannel()); m.position = g.transform.localPosition; m.rotation = g.transform.localRotation; m.time = time; byte[] data1 = network_utils.nData.Instance.SerializeMsg <network_data.move_player>(m); Channel.GetNetwork().Send(id, data1); if (IsCockpitUsedByMe()) { network_data.move_player m2 = new network_data.move_player(); m2.set(ShipContID, Game.GetComponent <channel>().GetChannel()); m2.position = transform.localPosition; m2.rotation = transform.localRotation; m2.velocity = targetVelocity; m2.time = time; byte[] data = network_utils.nData.Instance.SerializeMsg <network_data.move_player>(m2); Game.GetComponent <channel>().GetNetwork().Send(GetComponent <channel>().GetChannel(), data); } } } else { if (duration > TimeSpan.FromMilliseconds(100)) { last_clientupdate = now; network_data.move_player m = new network_data.move_player(); IDictionaryEnumerator i = Channel.FirstEntity(); while (i.MoveNext()) { GameObject g = (GameObject)i.Value; m.set((int)i.Key, Channel.GetChannel()); m.position = ((GameObject)i.Value).transform.localPosition; m.rotation = ((GameObject)i.Value).transform.localRotation; byte[] data1 = network_utils.nData.Instance.SerializeMsg <network_data.move_player>(m); Channel.SendToChannel(ref data1); } } } }
public override void ProcessMessage(ref byte[] message) { network_utils.HEADER header = network_utils.nData.Instance.DeserializeMsg <network_utils.HEADER>(message); if (header.signum != network_utils.SIGNUM.BIN) { return; } switch (header.command) { case (int)network_data.COMMANDS.center_ship: { network_data.enter_ship com = network_utils.nData.Instance.DeserializeMsg <network_data.enter_ship>(message); if (Channel.GetNetwork().IsClient() == false) { GameObject g = GetNextSpawnPoint(); SpawnPlayer(com.header.containerID, Channel.GetNetwork().IsClient(), false, g.transform.localPosition, g.transform.localRotation, 0); } } break; case (int)network_data.COMMANDS.ccreate_player: { network_data.create_player com = network_utils.nData.Instance.DeserializeMsg <network_data.create_player>(message); if (Channel.GetNetwork().IsClient() == true) { SpawnPlayer(com.header.containerID, Channel.GetNetwork().IsClient(), Channel.GetNetwork().GetComponent <client>().ingameContID == com.header.containerID, com.position, com.rotation, 0); } } break; case (int)network_data.COMMANDS.cmove_player: { network_data.move_player com = network_utils.nData.Instance.DeserializeMsg <network_data.move_player>(message); if (Channel.GetNetwork().IsClient()) { if (Channel.GetNetwork().GetComponent <client>().ingameContID != com.header.containerID) { GameObject g = Channel.GetEntity(com.header.containerID); if (g != null) { g.GetComponent <puppet>().SetTransform(com.position, com.rotation, puppet.trans_flag_position | puppet.trans_flag_rotation, com.time); } } } else { GameObject g = Channel.GetEntity(com.header.containerID); if (g != null) { g.GetComponent <puppet>().SetTransform(com.position, com.rotation, puppet.trans_flag_position | puppet.trans_flag_rotation, com.time); } } } break; case (int)network_data.COMMANDS.cdisconnect: { network_data.disconnect com = network_utils.nData.Instance.DeserializeMsg <network_data.disconnect>(message); UnregisterEntity(com.header.containerID); } break; case (int)network_data.COMMANDS.ctrigger: { network_data.trigger com = network_utils.nData.Instance.DeserializeMsg <network_data.trigger>(message); if (Triggers.ContainsKey(com.netID)) { trigger t = Triggers[com.netID]; if (Channel.GetNetwork().IsClient()) { if (com.accept) { t.SetTrigger(com.count, com.on); t.GetLink().Accept(com.on, com.header.containerID); t.DoActivate(com.header.containerID); } } else { t.TriggerRequest(com.header.containerID); t.DoActivate(com.header.containerID); } } } break; } }
public override void ProcessMessage(ref byte[] message) { network_utils.HEADER header = network_utils.nData.Instance.DeserializeMsg <network_utils.HEADER>(message); if (header.signum != network_utils.SIGNUM.BIN) { return; } switch (header.command) { case (int)network_data.COMMANDS.cmove_player: { network_data.move_player com = network_utils.nData.Instance.DeserializeMsg <network_data.move_player>(message); if (Channel.GetNetwork().IsClient()) { GameObject g = Channel.GetEntity(com.header.containerID); ship s = g.GetComponent <ship>(); if (s != null) { if (!s.IsCockpitUsedByMe()) { g.GetComponent <ship>().SetTransform(com.position, com.rotation, puppet.trans_flag_position | puppet.trans_flag_rotation, com.time); g.GetComponent <ship>().SetMoveVector(com.position); g.GetComponent <ship>().SetVelocity(com.velocity); } else { g.GetComponent <ship>().SetTransform(com.position, com.rotation, puppet.trans_flag_position, com.time); } } } else { // g.transform.rotation = com.rotation; GameObject g = Channel.GetEntity(com.header.containerID); if (g == null) { Debug.Log("ShipID " + com.header.containerID + " not found"); } else { g.GetComponent <ship>().SetTransform(com.position, com.rotation, puppet.trans_flag_rotation, Time.time); // g.GetComponent<ship>().SetTransform(com.position,com.rotation); g.GetComponent <ship>().SetMoveVector(com.position); g.GetComponent <ship>().SetVelocity(com.velocity); byte[] data1 = network_utils.nData.Instance.SerializeMsg <network_data.move_player>(com); // g.GetComponent<ship>().GetChannel().SendToChannel(ref data1); } } /* if (Channel.GetNetwork().IsClient()) * { * int ownid = Channel.GetNetwork().GetComponent<client>().ingameContID; * GameObject g = Channel.GetEntity(com.header.containerID); * if (g != null) * { * g.GetComponent<puppet>().SetTransform(com.position, com.rotation); * } * } * else * { * GameObject g = Channel.GetEntity(com.header.containerID); * if (g != null) * { * g.GetComponent<puppet>().SetTransform(com.position, com.rotation); * g.GetComponent<ship>().SetVelocity(com.velocity); * } * } */ } break; } }