Skip to content

Commit

Permalink
Finish updating Riptide to v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-weiland committed Oct 9, 2022
1 parent 31a379c commit 14abfe1
Show file tree
Hide file tree
Showing 15 changed files with 61 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
github: tom-weiland # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: tomweiland # Replace with a single Ko-fi username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Steamworks;
using UnityEngine;

namespace RiptideDemos.SteamTransport.PlayerHosted
namespace Riptide.Demos.Steam.PlayerHosted
{
public class LobbyManager : MonoBehaviour
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
using Riptide;
using Riptide.Transports.Steam;
using Riptide.Transports.Steam;
using Riptide.Utils;
using System;
using UnityEngine;

namespace RiptideDemos.SteamTransport.PlayerHosted
namespace Riptide.Demos.Steam.PlayerHosted
{
public enum ServerToClientId : ushort
{
spawnPlayer = 1,
playerMovement,
SpawnPlayer = 1,
PlayerMovement,
}
public enum ClientToServerId : ushort
{
playerName = 1,
playerInput,
PlayerName = 1,
PlayerInput,
}

public class NetworkManager : MonoBehaviour
Expand Down Expand Up @@ -82,9 +81,9 @@ private void Start()
private void FixedUpdate()
{
if (Server.IsRunning)
Server.Tick();
Server.Update();

Client.Tick();
Client.Update();
}

private void OnApplicationQuit()
Expand Down Expand Up @@ -114,7 +113,7 @@ internal void DisconnectClient()
Destroy(player.gameObject);
}

private void NewPlayerConnected(object sender, ServerClientConnectedEventArgs e)
private void NewPlayerConnected(object sender, ServerConnectedEventArgs e)
{
foreach (ServerPlayer player in ServerPlayer.List.Values)
{
Expand All @@ -123,15 +122,15 @@ private void NewPlayerConnected(object sender, ServerClientConnectedEventArgs e)
}
}

private void ServerPlayerLeft(object sender, ClientDisconnectedEventArgs e)
private void ServerPlayerLeft(object sender, ServerDisconnectedEventArgs e)
{
Destroy(ServerPlayer.List[e.Id].gameObject);
Destroy(ServerPlayer.List[e.Client.Id].gameObject);
}

private void DidConnect(object sender, EventArgs e)
{
Message message = Message.Create(MessageSendMode.reliable, ClientToServerId.playerName);
message.Add(Steamworks.SteamFriends.GetPersonaName());
Message message = Message.Create(MessageSendMode.Reliable, ClientToServerId.PlayerName);
message.AddString(Steamworks.SteamFriends.GetPersonaName());
Client.Send(message);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using UnityEngine;

namespace RiptideDemos.SteamTransport.PlayerHosted
namespace Riptide.Demos.Steam.PlayerHosted
{
public class CameraController : MonoBehaviour
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using Riptide;
using System.Collections.Generic;
using System.Collections.Generic;
using UnityEngine;

namespace RiptideDemos.SteamTransport.PlayerHosted
namespace Riptide.Demos.Steam.PlayerHosted
{
public class ClientPlayer : MonoBehaviour
{
Expand Down Expand Up @@ -42,13 +41,13 @@ public static void Spawn(ushort id, string username, Vector3 position)
}

#region Messages
[MessageHandler((ushort)ServerToClientId.spawnPlayer, NetworkManager.PlayerHostedDemoMessageHandlerGroupId)]
[MessageHandler((ushort)ServerToClientId.SpawnPlayer, NetworkManager.PlayerHostedDemoMessageHandlerGroupId)]
private static void SpawnPlayer(Message message)
{
Spawn(message.GetUShort(), message.GetString(), message.GetVector3());
}

[MessageHandler((ushort)ServerToClientId.playerMovement, NetworkManager.PlayerHostedDemoMessageHandlerGroupId)]
[MessageHandler((ushort)ServerToClientId.PlayerMovement, NetworkManager.PlayerHostedDemoMessageHandlerGroupId)]
private static void PlayerMovement(Message message)
{
ushort playerId = message.GetUShort();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Riptide;
using UnityEngine;
using UnityEngine;

namespace RiptideDemos.SteamTransport.PlayerHosted
namespace Riptide.Demos.Steam.PlayerHosted
{
public class PlayerInput : MonoBehaviour
{
Expand Down Expand Up @@ -44,9 +43,9 @@ private void FixedUpdate()
#region Messages
private void SendInput()
{
Message message = Message.Create(MessageSendMode.unreliable, ClientToServerId.playerInput);
message.Add(inputs, false);
message.Add(camTransform.forward);
Message message = Message.Create(MessageSendMode.Unreliable, ClientToServerId.PlayerInput);
message.AddBools(inputs, false);
message.AddVector3(camTransform.forward);
NetworkManager.Singleton.Client.Send(message);
}
#endregion
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Riptide;
using UnityEngine;
using UnityEngine;

namespace RiptideDemos.SteamTransport.PlayerHosted
namespace Riptide.Demos.Steam.PlayerHosted
{
[RequireComponent(typeof(CharacterController))]
public class PlayerMovement : MonoBehaviour
Expand Down Expand Up @@ -73,10 +72,10 @@ private void Move(Vector2 inputDirection)
#region Messages
private void SendMovement()
{
Message message = Message.Create(MessageSendMode.unreliable, ServerToClientId.playerMovement);
message.Add(player.Id);
message.Add(transform.position);
message.Add(transform.forward);
Message message = Message.Create(MessageSendMode.Unreliable, ServerToClientId.PlayerMovement);
message.AddUShort(player.Id);
message.AddVector3(transform.position);
message.AddVector3(transform.forward);
NetworkManager.Singleton.Server.SendToAll(message);
}
#endregion
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using UnityEngine;
using UnityEngine;
using UnityEngine.UI;

namespace RiptideDemos.SteamTransport.PlayerHosted
namespace Riptide.Demos.Steam.PlayerHosted
{
internal class PlayerUIManager : MonoBehaviour
{
Expand All @@ -18,4 +18,4 @@ internal void SetName(string _name)
usernameText.text = _name;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using Riptide;
using System.Collections.Generic;
using System.Collections.Generic;
using UnityEngine;

namespace RiptideDemos.SteamTransport.PlayerHosted
namespace Riptide.Demos.Steam.PlayerHosted
{
[RequireComponent(typeof(PlayerMovement))]
public class ServerPlayer : MonoBehaviour
Expand Down Expand Up @@ -47,29 +46,29 @@ public static void Spawn(ushort id, string username)
/// <param name="toClient">The client to send the message to.</param>
public void SendSpawn(ushort toClient)
{
NetworkManager.Singleton.Server.Send(GetSpawnData(Message.Create(MessageSendMode.reliable, ServerToClientId.spawnPlayer)), toClient);
NetworkManager.Singleton.Server.Send(GetSpawnData(Message.Create(MessageSendMode.Reliable, ServerToClientId.SpawnPlayer)), toClient);
}
/// <summary>Sends a player's info to all clients.</summary>
private void SendSpawn()
{
NetworkManager.Singleton.Server.SendToAll(GetSpawnData(Message.Create(MessageSendMode.reliable, ServerToClientId.spawnPlayer)));
NetworkManager.Singleton.Server.SendToAll(GetSpawnData(Message.Create(MessageSendMode.Reliable, ServerToClientId.SpawnPlayer)));
}

private Message GetSpawnData(Message message)
{
message.Add(Id);
message.Add(Username);
message.Add(transform.position);
message.AddUShort(Id);
message.AddString(Username);
message.AddVector3(transform.position);
return message;
}

[MessageHandler((ushort)ClientToServerId.playerName, NetworkManager.PlayerHostedDemoMessageHandlerGroupId)]
[MessageHandler((ushort)ClientToServerId.PlayerName, NetworkManager.PlayerHostedDemoMessageHandlerGroupId)]
private static void PlayerName(ushort fromClientId, Message message)
{
Spawn(fromClientId, message.GetString());
}

[MessageHandler((ushort)ClientToServerId.playerInput, NetworkManager.PlayerHostedDemoMessageHandlerGroupId)]
[MessageHandler((ushort)ClientToServerId.PlayerInput, NetworkManager.PlayerHostedDemoMessageHandlerGroupId)]
private static void PlayerInput(ushort fromClientId, Message message)
{
ServerPlayer player = List[fromClientId];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using UnityEngine;
using UnityEngine.UI;

namespace RiptideDemos.SteamTransport.PlayerHosted
namespace Riptide.Demos.Steam.PlayerHosted
{
public class UIManager : MonoBehaviour
{
Expand Down
6 changes: 3 additions & 3 deletions Assets/RiptideSteamTransport/Transport/SteamClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ private void OnConnectionStatusChanged(SteamNetConnectionStatusChangedCallback_t

case ESteamNetworkingConnectionState.k_ESteamNetworkingConnectionState_ClosedByPeer:
SteamNetworkingSockets.CloseConnection(callback.m_hConn, 0, "Closed by peer", false);
OnDisconnected(DisconnectReason.disconnected);
OnDisconnected(DisconnectReason.Disconnected);
break;

case ESteamNetworkingConnectionState.k_ESteamNetworkingConnectionState_ProblemDetectedLocally:
SteamNetworkingSockets.CloseConnection(callback.m_hConn, 0, "Problem detected", false);
OnDisconnected(DisconnectReason.transportError);
OnDisconnected(DisconnectReason.TransportError);
break;

default:
Expand All @@ -158,7 +158,7 @@ private void OnConnectionStatusChanged(SteamNetConnectionStatusChangedCallback_t
}
}

public void Tick()
public void Poll()
{
if (steamConnection != null)
Receive(steamConnection);
Expand Down
6 changes: 3 additions & 3 deletions Assets/RiptideSteamTransport/Transport/SteamServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ private void OnConnectionStatusChanged(SteamNetConnectionStatusChangedCallback_t

case ESteamNetworkingConnectionState.k_ESteamNetworkingConnectionState_ClosedByPeer:
SteamNetworkingSockets.CloseConnection(callback.m_hConn, 0, "Closed by peer", false);
OnDisconnected(clientSteamId, DisconnectReason.disconnected);
OnDisconnected(clientSteamId, DisconnectReason.Disconnected);
break;

case ESteamNetworkingConnectionState.k_ESteamNetworkingConnectionState_ProblemDetectedLocally:
SteamNetworkingSockets.CloseConnection(callback.m_hConn, 0, "Problem detected", false);
OnDisconnected(clientSteamId, DisconnectReason.transportError);
OnDisconnected(clientSteamId, DisconnectReason.TransportError);
break;

default:
Expand Down Expand Up @@ -101,7 +101,7 @@ public void Close(Connection connection)
}
}

public void Tick()
public void Poll()
{
foreach (SteamConnection connection in connections.Values)
Receive(connection);
Expand Down
2 changes: 1 addition & 1 deletion Packages/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"com.unity.textmeshpro": "3.0.6",
"com.unity.timeline": "1.4.8",
"com.unity.ugui": "1.0.0",
"net.tomweiland.riptidenetworking": "https://github.com/tom-weiland/RiptideNetworking.git?path=/Unity/Packages/Core",
"net.tomweiland.riptide": "https://github.com/RiptideNetworking/Riptide.git?path=/Packages/Core#2.0.0",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
"com.unity.modules.animation": "1.0.0",
Expand Down
6 changes: 3 additions & 3 deletions Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,12 @@
"com.unity.modules.imgui": "1.0.0"
}
},
"net.tomweiland.riptidenetworking": {
"version": "https://github.com/tom-weiland/RiptideNetworking.git?path=/Unity/Packages/Core",
"net.tomweiland.riptide": {
"version": "https://github.com/RiptideNetworking/Riptide.git?path=/Packages/Core#2.0.0",
"depth": 0,
"source": "git",
"dependencies": {},
"hash": "e36b11a76b55ef4f48b6dc444ace6277d4400522"
"hash": "bb252ba2ea4bd1314d3f8f60bea490418635d06e"
},
"com.unity.modules.ai": {
"version": "1.0.0",
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
<div align="center">
<a href="https://github.com/RiptideNetworking/Riptide">
<img src="https://user-images.githubusercontent.com/51303091/189464842-ec077ebe-e927-46da-8251-e5ea93ffbea5.png" width="150px" height="auto">
<img src="https://riptide.tomweiland.net/images/logo.png" width="150px" height="auto">
</a>
</div>
<div align="center"><a href="https://tomweiland.net/youtube">YouTube</a>&emsp;<b>•</b>&emsp;<a href="https://discord.com/invite/tomweiland">Discord</a></div>
<div align="center"><a href="https://riptide.tomweiland.net">Docs</a>&emsp;<b>•</b>&emsp;<a href="https://discord.gg/tomweiland">Discord</a>&emsp;<b>•</b>&emsp;<a href="https://github.com/sponsors/tom-weiland">Donate</a></div>
<h1 align="center">Steam Transport for Riptide Networking</h1>

A transport for [Riptide Networking](https://github.com/RiptideNetworking/Riptide) that uses [SteamNetworkingSockets](https://partner.steamgames.com/doc/api/ISteamNetworkingSockets).

For a list of other available transports, see the [transports](https://github.com/RiptideNetworking/Riptide#low-level-transports) section of Riptide's main README.

## Dependencies

You must have both [Riptide Networking](https://github.com/RiptideNetworking/Riptide) and [Steamworks.NET](https://github.com/rlabrecque/Steamworks.NET) installed and set up before you can use this transport.

## Limitations

Only works on platforms supported by Steam.

## Donate
This transport is 100% free to use, but if you'd like to financially support the development of Riptide and its various transports, you can do so via [GitHub sponsors](https://github.com/sponsors/tom-weiland) or on [Ko-fi](https://ko-fi.com/tomweiland).

Riptide and its transports are 100% free to use, but if you'd like to financially support Riptide's development and get early access to new features, you can do so through [GitHub Sponsors](https://github.com/sponsors/tom-weiland).

## License

Distributed under the MIT license. See [LICENSE.md](LICENSE.md) for more information.

0 comments on commit 14abfe1

Please sign in to comment.