Skip to content
This repository was archived by the owner on Feb 20, 2022. It is now read-only.

Commit f4bf068

Browse files
author
Vincent Cantin
committed
Moved all the classes of the library to the “DDP” namespace.
1 parent e246ce9 commit f4bf068

File tree

14 files changed

+709
-663
lines changed

14 files changed

+709
-663
lines changed

unity-project/Assets/example/TestDdpAccount.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using UnityEngine;
22
using System.Collections;
3+
using DDP;
34

45
public class TestDdpAccount : MonoBehaviour {
56

unity-project/Assets/example/TestDdpClient.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using UnityEngine;
22
using System.Collections;
3+
using DDP;
34

45
public class TestDdpClient : MonoBehaviour {
56

unity-project/Assets/example/TestLocalDB.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using UnityEngine;
22
using System.Collections;
3+
using DDP;
34

45
public class TestLocalDB : MonoBehaviour {
56

unity-project/Assets/unity3d-ddp-client/account/DdpAccount.cs

Lines changed: 69 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -4,92 +4,96 @@
44
using System.Security.Cryptography;
55
using System.Collections;
66

7-
public class DdpAccount {
7+
namespace DDP {
88

9-
private DdpConnection connection;
9+
public class DdpAccount {
1010

11-
public bool isLogged;
12-
public string userId;
13-
public string token;
14-
public DateTime tokenExpiration;
11+
private DdpConnection connection;
1512

16-
public DdpError error;
13+
public bool isLogged;
14+
public string userId;
15+
public string token;
16+
public DateTime tokenExpiration;
1717

18-
public DdpAccount(DdpConnection connection) {
19-
this.connection = connection;
20-
}
18+
public DdpError error;
19+
20+
public DdpAccount(DdpConnection connection) {
21+
this.connection = connection;
22+
}
2123

22-
private JSONObject GetPasswordObj(string password) {
23-
string digest = BitConverter.ToString(
24-
new SHA256Managed().ComputeHash(Encoding.UTF8.GetBytes(password)))
25-
.Replace("-", "").ToLower();
24+
private JSONObject GetPasswordObj(string password) {
25+
string digest = BitConverter.ToString(
26+
new SHA256Managed().ComputeHash(Encoding.UTF8.GetBytes(password)))
27+
.Replace("-", "").ToLower();
2628

27-
JSONObject passwordObj = JSONObject.Create();
28-
passwordObj.AddField("digest", digest);
29-
passwordObj.AddField("algorithm", "sha-256");
29+
JSONObject passwordObj = JSONObject.Create();
30+
passwordObj.AddField("digest", digest);
31+
passwordObj.AddField("algorithm", "sha-256");
3032

31-
return passwordObj;
32-
}
33+
return passwordObj;
34+
}
3335

34-
private void HandleLoginResult(MethodCall loginCall) {
35-
error = loginCall.error;
36+
private void HandleLoginResult(MethodCall loginCall) {
37+
error = loginCall.error;
3638

37-
if (error == null) {
38-
JSONObject result = loginCall.result;
39-
isLogged = true;
40-
this.userId = result["id"].str;
41-
this.token = result["token"].str;
42-
this.tokenExpiration = result["tokenExpires"].GetDateTime();
39+
if (error == null) {
40+
JSONObject result = loginCall.result;
41+
isLogged = true;
42+
this.userId = result["id"].str;
43+
this.token = result["token"].str;
44+
this.tokenExpiration = result["tokenExpires"].GetDateTime();
45+
}
4346
}
44-
}
4547

46-
private void HandleLogoutResult(MethodCall logoutCall) {
47-
error = logoutCall.error;
48+
private void HandleLogoutResult(MethodCall logoutCall) {
49+
error = logoutCall.error;
4850

49-
if (error == null) {
50-
isLogged = false;
51-
this.userId = null;
52-
this.token = null;
53-
this.tokenExpiration = default(DateTime);
51+
if (error == null) {
52+
isLogged = false;
53+
this.userId = null;
54+
this.token = null;
55+
this.tokenExpiration = default(DateTime);
56+
}
5457
}
55-
}
5658

57-
public IEnumerator CreateUserAndLogin(string username, string password) {
58-
JSONObject loginPasswordObj = JSONObject.Create();
59-
loginPasswordObj.AddField("username", username);
60-
loginPasswordObj.AddField("password", GetPasswordObj(password));
59+
public IEnumerator CreateUserAndLogin(string username, string password) {
60+
JSONObject loginPasswordObj = JSONObject.Create();
61+
loginPasswordObj.AddField("username", username);
62+
loginPasswordObj.AddField("password", GetPasswordObj(password));
6163

62-
MethodCall loginCall = connection.Call("createUser", loginPasswordObj);
63-
yield return loginCall.WaitForResult();
64-
HandleLoginResult(loginCall);
65-
}
64+
MethodCall loginCall = connection.Call("createUser", loginPasswordObj);
65+
yield return loginCall.WaitForResult();
66+
HandleLoginResult(loginCall);
67+
}
6668

67-
public IEnumerator Login(string username, string password) {
68-
JSONObject userObj = JSONObject.Create();
69-
userObj.AddField("username", username);
69+
public IEnumerator Login(string username, string password) {
70+
JSONObject userObj = JSONObject.Create();
71+
userObj.AddField("username", username);
7072

71-
JSONObject loginPasswordObj = JSONObject.Create();
72-
loginPasswordObj.AddField("user", userObj);
73-
loginPasswordObj.AddField("password", GetPasswordObj(password));
73+
JSONObject loginPasswordObj = JSONObject.Create();
74+
loginPasswordObj.AddField("user", userObj);
75+
loginPasswordObj.AddField("password", GetPasswordObj(password));
7476

75-
MethodCall loginCall = connection.Call("login", loginPasswordObj);
76-
yield return loginCall.WaitForResult();
77-
HandleLoginResult(loginCall);
78-
}
77+
MethodCall loginCall = connection.Call("login", loginPasswordObj);
78+
yield return loginCall.WaitForResult();
79+
HandleLoginResult(loginCall);
80+
}
7981

80-
public IEnumerator ResumeSession(string token) {
81-
JSONObject tokenObj = JSONObject.Create();
82-
tokenObj.AddField("resume", token);
82+
public IEnumerator ResumeSession(string token) {
83+
JSONObject tokenObj = JSONObject.Create();
84+
tokenObj.AddField("resume", token);
8385

84-
MethodCall loginCall = connection.Call("login", tokenObj);
85-
yield return loginCall.WaitForResult();
86-
HandleLoginResult(loginCall);
87-
}
86+
MethodCall loginCall = connection.Call("login", tokenObj);
87+
yield return loginCall.WaitForResult();
88+
HandleLoginResult(loginCall);
89+
}
90+
91+
public IEnumerator Logout() {
92+
MethodCall logoutCall = connection.Call("logout");
93+
yield return logoutCall.WaitForResult();
94+
HandleLogoutResult(logoutCall);
95+
}
8896

89-
public IEnumerator Logout() {
90-
MethodCall logoutCall = connection.Call("logout");
91-
yield return logoutCall.WaitForResult();
92-
HandleLogoutResult(logoutCall);
9397
}
9498

9599
}

0 commit comments

Comments
 (0)