private ComponentChange ParseChange(RTData data) { uint i = 1; long entityId = data.GetInt(i).Value; i++; bool isRemoved = data.GetInt(i) == 1; i++; int componentTypeInd = data.GetInt(i).Value; i++; Type t = EntityComponent.GetType(componentTypeInd); EntityComponent after = EntityComponent.Create(t, data, i); return(new ComponentChange(entityId, isRemoved, null, after)); }
void OnCollisionEnter(Collision _col) { Debug.Log(_col.gameObject.name); using (RTData data = RTData.Get()) { data.SetInt(1, ownerPeerId); MultiplayerNetworkingManager.Instance().GetRTSession().SendData(6, GameSparks.RT.GameSparksRT.DeliveryIntent.UNRELIABLE_SEQUENCED, data); Collide(); } }
void SendTurretFireUpdate() { using (RTData data = RTData.Get()) { data.SetInt(1, 0); _gameSparksManager.RTSession.SendData( MultiplayerCodes.PLAYER_BULLETS.Int(), GameSparksRT.DeliveryIntent.UNRELIABLE_SEQUENCED, data ); } }
//The method to use to send data to a session. public int SendRTDataAndBytes(int opCode, GameSparksRT.DeliveryIntent deliveryIntent, ArraySegment <byte> unstructuredData, RTData structuredData, params int[] targetPlayers) { if (session != null) { return(session.SendRTDataAndBytes(opCode, deliveryIntent, unstructuredData, structuredData, targetPlayers)); } return(-1); }
void SendHealthUpdate(float hp) { using (RTData data = RTData.Get()) { data.SetFloat(1, hp); GameSparks.RTSession.SendData( MultiplayerCodes.PLAYER_HEALTH.Int(), GameSparksRT.DeliveryIntent.RELIABLE, data ); } }
private void timer2_Tick(object sender, EventArgs e) { lock (ClientListenManager.NewData) { this.data = ClientListenManager.NewData; } if (this.data != null) { byte[] bytes = this.GetBytes(this.data); this.comm2.SendData(bytes, 0, bytes.Length); } }
private IEnumerator SendTimeStamp() { // send a packet with our current time using (RTData data = RTData.Get()) { data.SetLong(1, (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0)).TotalMilliseconds); // get the current time as unix timestamp RT_manager.SendData(101, GameSparks.RT.GameSparksRT.DeliveryIntent.UNRELIABLE_SEQUENCED, data, new int[] { 0 }); // send to peerId -> 0, which is the server } yield return(new WaitForSeconds(2f)); // wait 5 seconds StartCoroutine(SendTimeStamp()); // send the timestamp again }
private void UpdateValues() { RTData newdata = null; lock (CacheInvoke.newdata) { newdata = CacheInvoke.newdata; } if (newdata == null) { MessageBox.Show("没有数据"); } else { string fDJLQYWD = string.Empty; switch (this.currenttypeid) { case 1: this.value2 = 70.0; if (newdata == null) { this.value1 = 0.0; return; } fDJLQYWD = newdata.FDJLQYWD; if (string.IsNullOrEmpty(fDJLQYWD)) { break; } this.value1 = Convert.ToDouble(fDJLQYWD.Remove(fDJLQYWD.IndexOf('℃'))); return; case 2: this.value2 = 800.0; if (newdata == null) { this.value1 = 0.0; break; } fDJLQYWD = newdata.FDJZS; if (string.IsNullOrEmpty(fDJLQYWD)) { break; } this.value1 = Convert.ToDouble(fDJLQYWD.Remove(fDJLQYWD.IndexOf('r'))); return; default: return; } } }
private void OnPacketReceived(RTPacket _packet) { switch (_packet.OpCode) { case (int)NetworkControl.FromServerOpCodes.SHOWMENU: FindObjectOfType <MenuCanvas>().ShowMenuPanel(); break; case (int)NetworkControl.FromServerOpCodes.STARTGAME: RTData planePosData = _packet.Data.GetData(1); Vector3 planePos = new Vector3((float)planePosData.GetFloat(1), 0, (float)planePosData.GetFloat(2)); RTData planeDirData = _packet.Data.GetData(2); Vector3 planeDir = new Vector3((float)planeDirData.GetFloat(1), 0, (float)planeDirData.GetFloat(2)); string displayName = _packet.Data.GetString(3); int skinIndex = (int)_packet.Data.GetInt(4); int planeId = (int)_packet.Data.GetInt(5); GameManager.Instance.SpawnPlane(planeId, true, planePos, planeDir, displayName, skinIndex); break; case (int)NetworkControl.FromServerOpCodes.SERVER_UPDATE: int planesCount = (int)_packet.Data.GetInt(1); for (uint i = 2; i < planesCount + 2; i++) { RTData planeData = _packet.Data.GetData(i); int id = (int)planeData.GetInt(1); RTData posData = planeData.GetData(2); Vector3 pos = new Vector3((float)posData.GetFloat(1), 0, (float)posData.GetFloat(2)); RTData dirData = planeData.GetData(3); Vector3 forward = new Vector3((float)dirData.GetFloat(1), 0, (float)dirData.GetFloat(2)); GameManager.Instance.UpdatePlane(id, pos, forward); } break; } }
public MatchCommand ParseCommand(int opCode, RTData data) { Func <RTData, MatchCommand> parser = null; if (!_parsers.TryGetValue(opCode, out parser)) { Debug.LogError("Unrecognised command received, opCode = " + opCode.ToString()); return(null); } MatchCommand command = parser(data); return(command); }
private void SendPing() { if (_session.ConnectState == GameSparksRT.ConnectState.Disconnected) { return; } var d = new RTData(); d.SetInt(1, GetNextRequestId()); d.SetLong(2, DateTime.UtcNow.Ticks); Console.WriteLine("Sending Ping Packet - OpCode: {0}", OpCode.Ping); _session.SendRTData((int)OpCode.Ping, GameSparksRT.DeliveryIntent.RELIABLE, d); }
public void SendPoints(float value) { using (RTData data = RTData.Get()) { float score = m_playerScore.Score; data.SetFloat(1, score); m_gameSparksManager.RTSession.SendData( MultiplayerCodes.GAME_POINTS.Int(), GameSparksRT.DeliveryIntent.RELIABLE, data ); } }
public static Vector4?GetVector4(this RTData data, uint index) { if (data.GetRTVector(index) != null) { RTVector vector = data.GetRTVector(index).Value; if (!vector.w.HasValue) { return(null); } return(new Vector4(vector.x.Value, vector.y.Value, vector.z.Value, vector.w.Value)); } return(null); }
internal void Reset() { if (data_val != null) { data_val.Dispose(); } long_val = null; float_val = null; double_val = null; data_val = null; string_val = null; vec_val = null; }
private void UpdateValues() { RTData rTData = null; lock (ClientListenManager.NewData) { rTData = ClientListenManager.NewData; } if (rTData != null) { string text = string.Empty; switch (this.currenttypeid) { case 1: this.value2 = 70.0; if (rTData == null) { this.value1 = 0.0; return; } text = rTData.FDJLQYWD; if (!string.IsNullOrEmpty(text)) { this.value1 = Convert.ToDouble(text.Remove(text.IndexOf('℃'))); return; } break; case 2: this.value2 = 600.0; if (rTData != null) { text = rTData.FDJZS; if (!string.IsNullOrEmpty(text)) { this.value1 = Convert.ToDouble(text.Remove(text.IndexOf('r'))); return; } } else { this.value1 = 0.0; } break; default: return; } } }
internal void SendInputData(SlimeType slimeType, int i, int j) { int other_player = PeerId == 1 ? 2 : 1; int[] targets = new int[] { other_player }; RTData data = new RTData(); data.SetInt(3, (int)slimeType); data.SetInt(1, i); data.SetInt(2, j); RtGS.SendData(1, GameSparksRT.DeliveryIntent.RELIABLE, data, targets); }
/// <summary> /// Send and sets this objects color for the user who called this function and for all other players /// </summary> /// <param name="_myColor">The color to be set for the user who called this function</param> /// <param name="_opponentsColor">The color to be set for everyone who did not call this function (everyone else)</param> /// <example><code> /// void SomeFunction() /// { /// gameobject.GetComponent<ASL.ASLObject>().SendAndSetClaim(() => /// { /// gameobject.GetComponent<ASL.ASLObject>().SendAndSetObjectColor(new Color(0, 0, 0, 1), new Color(1, 1, 1, 1)); /// }); /// } /// </code></example> public void SendAndSetObjectColor(Color _myColor, Color _opponentsColor) { if (m_Mine) { transform.GetComponent <Renderer>().material.color = _myColor; using (RTData data = RTData.Get()) { data.SetString((int)GameController.DataCode.Id, m_Id); data.SetVector4((int)GameController.DataCode.MyColor, _myColor); data.SetVector4((int)GameController.DataCode.OpponentColor, _opponentsColor); GameSparksManager.Instance().GetRTSession().SendData((int)GameSparksManager.OpCode.SetObjectColor, GameSparksRT.DeliveryIntent.RELIABLE, data); } } }
public void SendStartGame() { using (RTData data = RTData.Get()) { data.SetInt(1, 1); Debug.Log("Start Game"); m_gameSparksManager.RTSession.SendData( MultiplayerCodes.START_GAME.Int(), GameSparksRT.DeliveryIntent.UNRELIABLE, data ); } StartGame(); }
public static void SendTimeStamp(GameSparksRTUnity rtSession) { if (rtSession == null) { return; } using (RTData data = RTData.Get()) { long unixTime = GetUnixTime(); data.SetLong(1, (long)unixTime); rtSession.SendData((int)OpCodes.TimeStamp, GameSparksRT.DeliveryIntent.UNRELIABLE, data, SERVER_PEER_ID); } }
private void UpdateEnemiesSpawn(RTPacket packet) { RTData data = packet.Data; int id = data.GetInt(1).Value; Vector2 position = data.GetVector2(3).Value; position = SignsExt.Vector2Sign(position, (Signs)data.GetInt(4).Value); float rotation = data.GetFloat(5).Value; Vector2 velocity = data.GetVector2(6).Value; velocity = SignsExt.Vector3Sign(velocity, (Signs)data.GetInt(7).Value); m_enemyGenerator.GenerateEnemy(id, position, rotation, velocity, true); }
//The method to use to send data to a session. public int SendData(int opCode, GameSparksRT.DeliveryIntent deliveryIntent, RTData structuredData, params int[] targetPlayers) { #if UNITY_WEBGL && !UNITY_EDITOR return(SendRTDataAndBytes(opCode, deliveryIntent, new ArraySegment <byte>(), structuredData, targetPlayers)); #else if (session != null) { return(session.SendRTData(opCode, deliveryIntent, structuredData, targetPlayers)); } return(-1); #endif }
public void CardUseSend(string card_name, int pos_x, int pos_y, string id, string target_id) { using (RTData data = RTData.Get()) { data.SetString(1, card_name); data.SetInt(2, pos_x); data.SetInt(3, pos_y); data.SetString(4, id); data.SetString(5, target_id); RT_manager.SendData(123, GameSparks.RT.GameSparksRT.DeliveryIntent.UNRELIABLE_SEQUENCED, data, new int[] { 0 }); // send to peerId -> 0, which is the server } target = null; }
/// <summary> /// Sends the RPC. /// </summary> /// <param name="code">Code.</param> /// <param name="methodName">Method name.</param> /// <param name="targetPlayer">Target player.</param> /// <param name="isBuffered">If set to <c>true</c> is buffered.</param> /// <param name="isLocal">If set to <c>true</c> is local.</param> /// <param name="parameters">Parameters.</param> private void SendEvent_RPC(OpCode code, string methodName, int[] receiverIds, bool isBuffered, params object[] parameters) { SparkRPC rpc = new SparkRPC(Guid.Empty, methodName, receiverIds, LocalPlayer, parameters); using (RTData data = RTData.Get()) { data.SetString(1, SparkExtensions.Serialize(rpc)); sparkNetwork.SendData(Convert.ToInt32(code), GameSparksRT.DeliveryIntent.RELIABLE, data, receiverIds); } if (isBuffered) { LocalRPC_Buffer.Add(rpc); LocalRPC("Add_LocalRPC_Buffer", SparkTargets.Others, false, rpc); } }
public void GetRTData(object value) { RTData data = value as RTData; if ((data != null) && (ListenEvent != null)) { lock (NewData) { NewData = data; } if (!ClientSystemInfo.readyToExit && (ListenEvent != null)) { ListenEvent(null, new ListenEventArgs(SocketInfoType.RealTimeData, data)); } } }
public static void SendPlayerMovement(Survivor survivor, GameSparksRTUnity rtSession) { using (RTData data = RTData.Get()) { data.SetVector3(1, survivor.transform.position); data.SetVector3(2, survivor.transform.rotation.eulerAngles); data.SetVector3(3, survivor.GetComponent <Rigidbody>().velocity); data.SetVector4(4, survivor.UserControl.Move); float jumpFloat = survivor.UserControl.Jump ? 1 : 0; float crouchFloat = survivor.UserControl.Crouch ? 1 : 0; data.SetVector2(5, new Vector2(jumpFloat, crouchFloat)); rtSession.SendData((int)OpCodes.PlayerTransform, GameSparksRT.DeliveryIntent.UNRELIABLE_SEQUENCED, data); } }
/// <summary>Serialize the instance into the stream</summary> internal static void Serialize(Stream stream, Packet instance) { // Key for field: 1, Varint stream.WriteByte(8); global::GameSparks.RT.Proto.ProtocolParser.WriteZInt32(stream, instance.OpCode); if (instance.SequenceNumber != null) { // Key for field: 2, Varint stream.WriteByte(16); global::GameSparks.RT.Proto.ProtocolParser.WriteUInt64(stream, (ulong)instance.SequenceNumber.Value); } if (instance.RequestId != null) { // Key for field: 3, Varint stream.WriteByte(24); global::GameSparks.RT.Proto.ProtocolParser.WriteUInt64(stream, (ulong)instance.RequestId.Value); } if (instance.TargetPlayers != null) { foreach (var i4 in instance.TargetPlayers) { // Key for field: 4, Varint stream.WriteByte(32); global::GameSparks.RT.Proto.ProtocolParser.WriteUInt64(stream, (ulong)i4); } } if (instance.Sender != null) { // Key for field: 5, Varint stream.WriteByte(40); global::GameSparks.RT.Proto.ProtocolParser.WriteUInt64(stream, (ulong)instance.Sender.Value); } if (instance.Reliable != null) { // Key for field: 6, Varint stream.WriteByte(48); global::GameSparks.RT.Proto.ProtocolParser.WriteBool(stream, instance.Reliable.Value); } if (instance.Data != null) { stream.WriteByte(114); RTData.WriteRTData(stream, instance.Data); } instance.WritePayload(stream); }
public void SetPlayerReady(bool value) { Debug.Log("GameSparksManager::SetReadyState"); if (value == true) { using (RTData data = RTData.Get()) { data.SetInt(1, PeerId()); SendRTData(OpCodes.PlayerReady, GameSparksRT.DeliveryIntent.RELIABLE, data); } } else { throw new NotImplementedException(); } }
public void SetSpectatorMode() { for (int i = 0; i < playerList.Count; i++) { if (playerList[i].isUser) { using (RTData data = RTData.Get()) { // Data doesn't need to contain anything since we are just notifying the other peers that players has attacked MultiplayerNetworkingManager.Instance().GetRTSession().SendData(5, GameSparks.RT.GameSparksRT.DeliveryIntent.UNRELIABLE, data); // send the data at op-code 3 playerList[i].EnterSpectatorMode(); spectateButton.interactable = false; } break; } } }
// This function ensures that the player can only attack after a certain cooldown private IEnumerator AbilityCooldown() { canAttack = false; // Send a data packet to GameSparks to notify opponent that player has attacked using (RTData data = RTData.Get()) { // Data doesn't need to contain anything since we are just notifying the other peers that players has attacked MultiplayerNetworkingManager.Instance().GetRTSession().SendData(3, GameSparks.RT.GameSparksRT.DeliveryIntent.UNRELIABLE, data); // send the data at op-code 3 TriggerAbility(); } // Wait for the cooldown period before letting the player attack again yield return(new WaitForSeconds(coolDown)); canAttack = true; }
//The method to use to send data to a session. public int SendRTDataAndBytes(int opCode, GameSparksRT.DeliveryIntent deliveryIntent, ArraySegment <byte> unstructuredData, RTData structuredData, params int[] targetPlayers) { #if UNITY_WEBGL && !UNITY_EDITOR string payloadString = ""; string dataJson = ""; string targetPlayersJson = ""; if (unstructuredData.Count > 0) { payloadString = System.Text.Encoding.UTF8.GetString(unstructuredData.Array, 0, unstructuredData.Array.Length); } if (structuredData != null) { JsonObject o = CreateObjectData(structuredData); dataJson = o.ToString(); //Debug.Log(dataJson); } if (targetPlayers != null) { JsonArray a = new JsonArray(targetPlayers.Length); for (int i = 0; i < targetPlayers.Length; i++) { a.Add(targetPlayers[i]); } targetPlayersJson = a.ToString(); } return(GSSendRTDataAndBytes(currSessionId, opCode, (int)deliveryIntent, payloadString, dataJson, targetPlayersJson)); #else if (session != null) { return(session.SendRTDataAndBytes(opCode, deliveryIntent, unstructuredData, structuredData, targetPlayers)); } return(-1); #endif }
//The method to use to send data to a session. public int SendData(int opCode, GameSparksRT.DeliveryIntent deliveryIntent, RTData structuredData, params int[] targetPlayers) { if(session != null){ return session.SendRTData(opCode, deliveryIntent, structuredData, targetPlayers); } return -1; }
//The method to use to send data to a session. public int SendRTDataAndBytes(int opCode, GameSparksRT.DeliveryIntent deliveryIntent, ArraySegment<byte> unstructuredData, RTData structuredData, params int[] targetPlayers) { if(session != null){ return session.SendRTDataAndBytes(opCode, deliveryIntent, unstructuredData, structuredData, targetPlayers); } return -1; }