/// <summary>
/// Login to the server
/// </summary>
Login = 100,
Next we need to add our parameter codes after DebugMessage in ParameterCode.cs:
/// <summary>
/// The player's username /// </summary>
UserName = 70, /// <summary>
/// The player's password /// </summary>
Password = 71,Now that we have our operation code and parameter code, we can recompile the Common project and make sure it is in the same directory as our AegisBorn3dPhoton project so that Unity3d can use it. Now if you read through the SmartFoxServer blog posts, you'll know I hate building stuff manually, meaning if I'm going to build a message to send to a server, I build it in a class/function so that I don't accidentally have 15 versions floating around in code. Exit Games did this nicely with a static class called Operations. However, I feel lumping them all into the same class defeats the purpose of a class. So I'm going to build a file called LoginOperations and I'm going to put it in a directory called _Operations under _Scripts:
using System.Collections;
using AegisBornCommon;
public static class LoginOperations
{
public static void Login(Game game, string username, string password)
{
var vartable = new Hashtable
{
{(byte) ParameterCode.UserName, username},
{(byte) ParameterCode.Password, password}
};
game.SendOp(OperationCode.Login, vartable, true, 0, true);
}
}
And that will now send the login operation to the server. Next we are going to grab our old GUI code from the SmartFoxServer code and put it into the Login.cs OnGUI with some minor modifications:
private Game _engine;
void Start()
{
_engine = MMOEngine.Engine;
_engine.afterKeysExchanged += AfterKeysExchanged;
}
private string _username = "";
private string _password = "";
void OnGUI()
{
GUI.Label(new Rect(10, 116, 100, 100), "Userame: ");
_username = GUI.TextField(new Rect(100, 116, 200, 20), _username, 25);
GUI.Label(new Rect(10, 141, 100, 100), "Password: ");
_password = GUI.PasswordField(new Rect(100, 141, 200, 20), _password, '*', 25);
GUI.Label(new Rect(10, 225, 400, 100), _engine.State.ToString());
if (GUI.Button(new Rect(100, 165, 100, 25), "Login") || (Event.current.type == EventType.keyDown && Event.current.character == '\n'))
{
var peer = new PhotonPeer(_engine, false);
_engine.Initialize(peer, "localhost:5055", "AegisBorn");
}
if (GUI.Button(new Rect(100, 195, 100, 25), "Logout"))
{
_engine.SetDisconnected(0);
}
}
public void AfterKeysExchanged()
{
LoginOperations.Login(_engine, _username, _password);
}
void Start()
{
_engine = MMOEngine.Engine;
_engine.afterKeysExchanged += AfterKeysExchanged;
}
private string _username = "";
private string _password = "";
void OnGUI()
{
GUI.Label(new Rect(10, 116, 100, 100), "Userame: ");
_username = GUI.TextField(new Rect(100, 116, 200, 20), _username, 25);
GUI.Label(new Rect(10, 141, 100, 100), "Password: ");
_password = GUI.PasswordField(new Rect(100, 141, 200, 20), _password, '*', 25);
GUI.Label(new Rect(10, 225, 400, 100), _engine.State.ToString());
if (GUI.Button(new Rect(100, 165, 100, 25), "Login") || (Event.current.type == EventType.keyDown && Event.current.character == '\n'))
{
var peer = new PhotonPeer(_engine, false);
_engine.Initialize(peer, "localhost:5055", "AegisBorn");
}
if (GUI.Button(new Rect(100, 195, 100, 25), "Logout"))
{
_engine.SetDisconnected(0);
}
}
public void AfterKeysExchanged()
{
LoginOperations.Login(_engine, _username, _password);
}
With encryption in place, we are now sending the server our username and password encrypted. The server will only send a response stating that it got the message.
If you were to run the program at this point, you will see that we have our login screen, when you click Login you will see the state transfer from Disconnected to WaitingForConnect to Connected. The log should have a message stating connected and then Keys Exchanged and then an unknown response to our Login operation.
Next time we will look into modifying the server with NHibernate to begin looking up our data and checking our login information.
As an aside, I've joined Empire Avenue. {EAV_BLOG_VER:caf99dc9611a09b5}
If you were to run the program at this point, you will see that we have our login screen, when you click Login you will see the state transfer from Disconnected to WaitingForConnect to Connected. The log should have a message stating connected and then Keys Exchanged and then an unknown response to our Login operation.
Next time we will look into modifying the server with NHibernate to begin looking up our data and checking our login information.
As an aside, I've joined Empire Avenue. {EAV_BLOG_VER:caf99dc9611a09b5}
No comments:
Post a Comment