players login now

master
Jordan Orelli 5 years ago
parent c2f781d3f0
commit 404c4acd3a

@ -12,6 +12,9 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: fb331b678c613734fa2ba6013e9cd499, type: 3}
m_Name: LoginInfo
m_EditorClassIdentifier:
playerName: DefaultPlayerName
password: defaultPassword
playerName: jordan
password: fartsock
startPosition: {x: 0, y: 10, z: 0}
sentLogin: 0
isLoggedIn: 1
loginFailed: 0

@ -1,5 +1,82 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &551004617
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 551004618}
- component: {fileID: 551004620}
- component: {fileID: 551004619}
m_Layer: 5
m_Name: Error Text
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &551004618
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 551004617}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1069633146321919518}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: -132}
m_SizeDelta: {x: 400, y: 80}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &551004620
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 551004617}
m_CullTransparentMesh: 0
--- !u!114 &551004619
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 551004617}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 708705254, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 0, b: 0.12598467, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 27
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 10
m_MaxSize: 40
m_Alignment: 4
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: Error Text Here
--- !u!1 &1069633144504421482
GameObject:
m_ObjectHideFlags: 0
@ -613,6 +690,7 @@ RectTransform:
- {fileID: 1069633144627678396}
- {fileID: 1069633145445280618}
- {fileID: 1069633146489083133}
- {fileID: 551004618}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -697,6 +775,7 @@ MonoBehaviour:
networking: {fileID: 11400000, guid: bb2274d4e981ac14fb9a2e043d04e95f, type: 2}
usernameField: {fileID: 1069633144627678397}
passwordField: {fileID: 1069633145445280619}
errorText: {fileID: 551004619}
--- !u!1 &1069633146489083132
GameObject:
m_ObjectHideFlags: 0
@ -733,7 +812,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: -144}
m_AnchoredPosition: {x: 0, y: -203}
m_SizeDelta: {x: 160, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &1069633146489083120

@ -7,4 +7,14 @@ public class LoginInfo : ScriptableObject {
public string playerName;
public string password;
public Vector3 startPosition;
// sentLogin is set true when we send the login, and set back to false when
// we receive the result
public bool sentLogin;
// isLoggedIn is set to true when we receive a successful login attempt
public bool isLoggedIn;
// loginFailed is set to true when we fail a login
public string loginError;
}

@ -10,15 +10,29 @@ public class MainMenu : MonoBehaviour
public Networking networking;
public InputField usernameField;
public InputField passwordField;
public Text errorText;
// Start is called before the first frame update
void Start() {
loginInfo.isLoggedIn = false;
loginInfo.sentLogin = false;
networking.Connect();
}
// Update is called once per frame
void Update() {
networking.CheckForMessages();
usernameField.interactable = !loginInfo.sentLogin;
passwordField.interactable = !loginInfo.sentLogin;
if (loginInfo.loginError == "") {
errorText.gameObject.SetActive(false);
} else {
errorText.text = loginInfo.loginError;
errorText.gameObject.SetActive(true);
}
if (loginInfo.isLoggedIn) {
SceneManager.LoadScene("MainLevel");
}
}
public void Login() {
@ -32,6 +46,5 @@ public class MainMenu : MonoBehaviour
loginInfo.playerName = username;
loginInfo.password = password;
networking.SendLogin();
SceneManager.LoadScene("MainLevel");
}
}

@ -78,6 +78,8 @@ public class Networking : ScriptableObject {
login.cmd = "login";
login.username = loginInfo.playerName;
login.password = loginInfo.password;
loginInfo.sentLogin = true;
loginInfo.loginError = "";
string msg = JsonUtility.ToJson(login);
ArraySegment<byte> buf = new ArraySegment<byte>(Encoding.UTF8.GetBytes(msg));
sock.SendAsync(buf, WebSocketMessageType.Text, true, CancellationToken.None);
@ -133,6 +135,18 @@ public class Networking : ScriptableObject {
}
break;
case "login-result":
Debug.LogFormat("received login result: {0}", parts[1]);
loginInfo.sentLogin = false;
LoginResult login = JsonUtility.FromJson<LoginResult>(parts[1]);
if (login.passed) {
loginInfo.isLoggedIn = true;
} else {
loginInfo.loginError = login.error;
Debug.LogErrorFormat("failed login: {0}", login.error);
}
break;
case "tick":
break;
@ -178,4 +192,9 @@ public class Networking : ScriptableObject {
public string username;
public string password;
}
private struct LoginResult {
public bool passed;
public string error;
}
}

Binary file not shown.
Loading…
Cancel
Save