Skip to content

Commit 85bd7d9

Browse files
committed
Update project repo to v0.1 prototype
1 parent a184579 commit 85bd7d9

File tree

1,103 files changed

+89779
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,103 files changed

+89779
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:String x:Key="/Default/CodeInspection/CSharpLanguageProject/LanguageLevel/@EntryValue">Default</s:String>
3+
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=assets_005Cscripts_005Ccameras/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

ReallyTinyStrategies_Script/Assets/Mirror.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ReallyTinyStrategies_Script/Assets/Mirror/Authenticators.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
using System;
2+
using System.Collections;
3+
using UnityEngine;
4+
5+
namespace Mirror.Authenticators
6+
{
7+
[AddComponentMenu("Network/Authenticators/BasicAuthenticator")]
8+
public class BasicAuthenticator : NetworkAuthenticator
9+
{
10+
[Header("Custom Properties")]
11+
12+
// set these in the inspector
13+
public string username;
14+
public string password;
15+
16+
#region Messages
17+
18+
public struct AuthRequestMessage : NetworkMessage
19+
{
20+
// use whatever credentials make sense for your game
21+
// for example, you might want to pass the accessToken if using oauth
22+
public string authUsername;
23+
public string authPassword;
24+
}
25+
26+
public struct AuthResponseMessage : NetworkMessage
27+
{
28+
public byte code;
29+
public string message;
30+
}
31+
32+
#endregion
33+
34+
#region Server
35+
36+
/// <summary>
37+
/// Called on server from StartServer to initialize the Authenticator
38+
/// <para>Server message handlers should be registered in this method.</para>
39+
/// </summary>
40+
public override void OnStartServer()
41+
{
42+
// register a handler for the authentication request we expect from client
43+
NetworkServer.RegisterHandler<AuthRequestMessage>(OnAuthRequestMessage, false);
44+
}
45+
46+
/// <summary>
47+
/// Called on server from StopServer to reset the Authenticator
48+
/// <para>Server message handlers should be registered in this method.</para>
49+
/// </summary>
50+
public override void OnStopServer()
51+
{
52+
// unregister the handler for the authentication request
53+
NetworkServer.UnregisterHandler<AuthRequestMessage>();
54+
}
55+
56+
/// <summary>
57+
/// Called on server from OnServerAuthenticateInternal when a client needs to authenticate
58+
/// </summary>
59+
/// <param name="conn">Connection to client.</param>
60+
public override void OnServerAuthenticate(NetworkConnection conn)
61+
{
62+
// do nothing...wait for AuthRequestMessage from client
63+
}
64+
65+
/// <summary>
66+
/// Called on server when the client's AuthRequestMessage arrives
67+
/// </summary>
68+
/// <param name="conn">Connection to client.</param>
69+
/// <param name="msg">The message payload</param>
70+
public void OnAuthRequestMessage(NetworkConnection conn, AuthRequestMessage msg)
71+
{
72+
// Debug.LogFormat(LogType.Log, "Authentication Request: {0} {1}", msg.authUsername, msg.authPassword);
73+
74+
// check the credentials by calling your web server, database table, playfab api, or any method appropriate.
75+
if (msg.authUsername == username && msg.authPassword == password)
76+
{
77+
// create and send msg to client so it knows to proceed
78+
AuthResponseMessage authResponseMessage = new AuthResponseMessage
79+
{
80+
code = 100,
81+
message = "Success"
82+
};
83+
84+
conn.Send(authResponseMessage);
85+
86+
// Accept the successful authentication
87+
ServerAccept(conn);
88+
}
89+
else
90+
{
91+
// create and send msg to client so it knows to disconnect
92+
AuthResponseMessage authResponseMessage = new AuthResponseMessage
93+
{
94+
code = 200,
95+
message = "Invalid Credentials"
96+
};
97+
98+
conn.Send(authResponseMessage);
99+
100+
// must set NetworkConnection isAuthenticated = false
101+
conn.isAuthenticated = false;
102+
103+
// disconnect the client after 1 second so that response message gets delivered
104+
StartCoroutine(DelayedDisconnect(conn, 1));
105+
}
106+
}
107+
108+
IEnumerator DelayedDisconnect(NetworkConnection conn, float waitTime)
109+
{
110+
yield return new WaitForSeconds(waitTime);
111+
112+
// Reject the unsuccessful authentication
113+
ServerReject(conn);
114+
}
115+
116+
#endregion
117+
118+
#region Client
119+
120+
/// <summary>
121+
/// Called on client from StartClient to initialize the Authenticator
122+
/// <para>Client message handlers should be registered in this method.</para>
123+
/// </summary>
124+
public override void OnStartClient()
125+
{
126+
// register a handler for the authentication response we expect from server
127+
NetworkClient.RegisterHandler<AuthResponseMessage>((Action<AuthResponseMessage>)OnAuthResponseMessage, false);
128+
}
129+
130+
/// <summary>
131+
/// Called on client from StopClient to reset the Authenticator
132+
/// <para>Client message handlers should be unregistered in this method.</para>
133+
/// </summary>
134+
public override void OnStopClient()
135+
{
136+
// unregister the handler for the authentication response
137+
NetworkClient.UnregisterHandler<AuthResponseMessage>();
138+
}
139+
140+
/// <summary>
141+
/// Called on client from OnClientAuthenticateInternal when a client needs to authenticate
142+
/// </summary>
143+
public override void OnClientAuthenticate()
144+
{
145+
AuthRequestMessage authRequestMessage = new AuthRequestMessage
146+
{
147+
authUsername = username,
148+
authPassword = password
149+
};
150+
151+
NetworkClient.connection.Send(authRequestMessage);
152+
}
153+
154+
/// <summary>
155+
/// Called on client when the server's AuthResponseMessage arrives
156+
/// </summary>
157+
/// <param name="msg">The message payload</param>
158+
public void OnAuthResponseMessage(AuthResponseMessage msg)
159+
{
160+
if (msg.code == 100)
161+
{
162+
// Debug.LogFormat(LogType.Log, "Authentication Response: {0}", msg.message);
163+
164+
// Authentication has been accepted
165+
ClientAccept();
166+
}
167+
else
168+
{
169+
Debug.LogError($"Authentication Response: {msg.message}");
170+
171+
// Authentication has been rejected
172+
ClientReject();
173+
}
174+
}
175+
176+
#endregion
177+
}
178+
}

ReallyTinyStrategies_Script/Assets/Mirror/Authenticators/BasicAuthenticator.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "Mirror.Authenticators",
3+
"references": [
4+
"Mirror"
5+
],
6+
"optionalUnityReferences": [],
7+
"includePlatforms": [],
8+
"excludePlatforms": [],
9+
"allowUnsafeCode": false,
10+
"overrideReferences": false,
11+
"precompiledReferences": [],
12+
"autoReferenced": true,
13+
"defineConstraints": []
14+
}

ReallyTinyStrategies_Script/Assets/Mirror/Authenticators/Mirror.Authenticators.asmdef.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using System.Collections;
2+
using UnityEngine;
3+
4+
namespace Mirror.Authenticators
5+
{
6+
/// <summary>
7+
/// An authenticator that disconnects connections if they don't
8+
/// authenticate within a specified time limit.
9+
/// </summary>
10+
[AddComponentMenu("Network/Authenticators/TimeoutAuthenticator")]
11+
public class TimeoutAuthenticator : NetworkAuthenticator
12+
{
13+
public NetworkAuthenticator authenticator;
14+
15+
[Range(0, 600), Tooltip("Timeout to auto-disconnect in seconds. Set to 0 for no timeout.")]
16+
public float timeout = 60;
17+
18+
public void Awake()
19+
{
20+
authenticator.OnServerAuthenticated.AddListener(connection => OnServerAuthenticated.Invoke(connection));
21+
authenticator.OnClientAuthenticated.AddListener(connection => OnClientAuthenticated.Invoke(connection));
22+
}
23+
24+
public override void OnStartServer()
25+
{
26+
authenticator.OnStartServer();
27+
}
28+
29+
public override void OnStopServer()
30+
{
31+
authenticator.OnStopServer();
32+
}
33+
34+
public override void OnStartClient()
35+
{
36+
authenticator.OnStartClient();
37+
}
38+
39+
public override void OnStopClient()
40+
{
41+
authenticator.OnStopClient();
42+
}
43+
44+
public override void OnServerAuthenticate(NetworkConnection conn)
45+
{
46+
authenticator.OnServerAuthenticate(conn);
47+
if (timeout > 0)
48+
StartCoroutine(BeginAuthentication(conn));
49+
}
50+
51+
public override void OnClientAuthenticate()
52+
{
53+
authenticator.OnClientAuthenticate();
54+
if (timeout > 0)
55+
StartCoroutine(BeginAuthentication(NetworkClient.connection));
56+
}
57+
58+
IEnumerator BeginAuthentication(NetworkConnection conn)
59+
{
60+
// Debug.Log($"Authentication countdown started {conn} {timeout}");
61+
yield return new WaitForSecondsRealtime(timeout);
62+
63+
if (!conn.isAuthenticated)
64+
{
65+
// Debug.Log($"Authentication Timeout {conn}");
66+
conn.Disconnect();
67+
}
68+
}
69+
}
70+
}

ReallyTinyStrategies_Script/Assets/Mirror/Authenticators/TimeoutAuthenticator.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ReallyTinyStrategies_Script/Assets/Mirror/CompilerSymbols.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)