public async Task <bool> Authenticate(DarkRiftClient client) { authSuccessToken = new TaskCompletionSource <ushort>(); using (var writer = DarkRiftWriter.Create()) { using (var message = Message.Create((ushort)MasterServerNoReplyTags.AuthRequest, writer)) { client.SendMessage(message, SendMode.Reliable); client.MessageReceived += SendPassword; await Task.Yield(); Task.WaitAny(Task.Delay(config.AuthRequestDelay), authSuccessToken.Task); if (authSuccessToken.Task.IsCompletedSuccessfully) { if (authSuccessToken.Task.Result != (ushort)MasterServerAuthReplies.Success) { throw new DRAuthException("Authentication failed"); } return(authSuccessToken.Task.Result == (ushort)MasterServerAuthReplies.Success); } else { authSuccessToken = null; throw new DRAuthException("Authentication Timed Out.."); } } } }
private void SendPassword(object sender, MessageReceivedEventArgs e) { var client = (DarkRiftClient)sender; if (e.Tag != (ushort)MasterServerNoReplyTags.PublicKey) { return; } client.MessageReceived -= SendPassword; using (var message = e.GetMessage()) { using (var reader = message.GetReader().DecryptReaderAES(config.SecretKeyArray)) { var publicKey = Convert.FromBase64String(reader.ReadString()); var commonKey = reader.ReadString(); using (var writer = DarkRiftWriter.Create()) { writer.Write(commonKey); using (var encryptedWriter = writer.EncryptWriterAES(publicKey)) { using (var reply = Message.Create((ushort)MasterServerNoReplyTags.Password, encryptedWriter)) { client.SendMessage(reply, SendMode.Reliable); client.MessageReceived += AcknowledgeAuth; } } } } } }
void UseMessageReceived(object sender, MessageReceivedEventArgs e) { using (Message message = e.GetMessage() as Message) { using (DarkRiftReader reader = message.GetReader()) { ushort objID = reader.ReadUInt16(); ushort useTag = reader.ReadUInt16(); using (DarkRiftWriter writer = DarkRiftWriter.Create()) { writer.Write(objID); writer.Write(useTag); using (Message useMessage = Message.Create(USE_TAG, writer)) { foreach (IClient c in ClientManager.GetAllClients().Where(x => x != e.Client)) { c.SendMessage(useMessage, SendMode.Reliable); } } } } } }
private void OnTurretUpdateMessage(Message message) { using (var reader = message.GetReader()) { var data = reader.ReadSerializable <TurretUpdateData>(); this.Turret.SetRotation(data.Rotation); using (var writer = DarkRiftWriter.Create()) { writer.Write(new TurretUpdateData { ClientId = this.Client.ID, Rotation = this.Turret.Rotation }); using (var updateMessage = Message.Create(MsgTags.TurretUpdate, writer)) { foreach (var client in this.Server.ClientManager.GetAllClients()) { if (client == this.Client) { continue; } client.SendMessage(updateMessage, SendMode.Unreliable); } } } } }
public void SendMovementMessage(ushort objID) { GameObject obj = objects[objID].gObj; using (DarkRiftWriter writer = DarkRiftWriter.Create()) { writer.Write(obj.GetComponent <NetworkTrackable>().uniqueID); Vector3 localPosition = obj.transform.localPosition; writer.Write(localPosition.x); writer.Write(localPosition.y); writer.Write(localPosition.z); Vector3 angles = obj.transform.rotation.eulerAngles; writer.Write(angles.x); writer.Write(angles.y); writer.Write(angles.z); using (Message message = Message.Create(PICKUP_TAG, writer)) client.SendMessage(message, SendMode.Unreliable); } }
private void SpawnPlayer(object sender, ClientConnectedEventArgs e) { Random r = new Random(); Player newPlayer = new Player(e.Client.ID, 0, (float)r.NextDouble() * 10f - 5f, (float)r.NextDouble() * 10f - 5f, (float)r.NextDouble() * 10f - 5f); using (DarkRiftWriter writer = DarkRiftWriter.Create()) { writer.Write(newPlayer.id); writer.Write(newPlayer.owner); using (Message m = Message.Create(Tags.spawnPlayerTag, writer)) { foreach (IClient client in players.Keys) { client.SendMessage(m, SendMode.Reliable); } } } players.Add(e.Client, newPlayer); using (DarkRiftWriter writer = DarkRiftWriter.Create()) { foreach (Player player in players.Values) { writer.Write(player.id); writer.Write(player.owner); } using (Message m = Message.Create(Tags.spawnPlayerTag, writer)) { e.Client.SendMessage(m, SendMode.Reliable); } } InitializeClient(e.Client); }
public void SpawnTurret(IClient[] clients) { if (clients.Length != turrets.Length) { Debug.LogError("Amount of clients to spawn does not match turrets"); return; } for (var i = 0; i < turrets.Length; i++) { this.turrets[i].SpawnTurret(clients[i]); } using (var writer = DarkRiftWriter.Create()) { for (ushort i = 0; i < turrets.Length; i++) { writer.Write(new TurretSpawnData { ID = turrets[i].Client.ID, Index = i }); } using (var spawnMessage = Message.Create(MsgTags.TurretSpawn, writer)) { foreach (var client in this.server.ClientManager.GetAllClients()) { client.SendMessage(spawnMessage, SendMode.Reliable); } } } }
private void GetLobbyRequestAndSend(MessageReceivedEventArgs e, DarkRiftReader r) { ushort page = r.ReadUInt16(); if (page == 0) { page = 1; } List <Lobby_Match> m = GetLobbysPerPage(page); if (m.Count == 0) { using (Message mes = Message.CreateEmpty(UDRMS_Tags.getLobbyMatchs)) e.Client.SendMessage(mes, SendMode.Reliable); return; } using (DarkRiftWriter w = DarkRiftWriter.Create()) { foreach (Lobby_Match match in m) { w.Write(match); // w.Write(match.matchID); // w.Write(match.matchOwner.client.ID); // w.Write((ushort)match.matchPlayers.Count); } using (Message mes = Message.Create(UDRMS_Tags.getLobbyMatchs, w)) e.Client.SendMessage(mes, SendMode.Reliable); } }
public Message GetGameStartMessage() { DarkRiftWriter writer = DarkRiftWriter.Create(); writer.Write(GameId); writer.Write((ushort)MapObjects.Count); foreach (MapObject go in MapObjects) { writer.Write(go.Type); if (go.Type == (ushort)MapObject.TypeIds.Wall) { writer.Write(go.Transform.Position.x); writer.Write(go.Transform.Position.y); BoxCollider b = (BoxCollider)go.Collider; writer.Write(b.Size.x); writer.Write(b.Size.y); } } writer.Write((byte)Players.Count); foreach (Player p in Players) { writer.Write(p.Name); writer.Write(p.Character.Owner.PlayerId); } Message m = Message.Create((ushort)Tags.GameStartMessage, writer); return(m); }
//This will be called when the user presses enter in the input field public void MessageEntered() { //Check we have a client to send from if (client == null) { Debug.LogError("No client assigned to Chat component!"); return; } //First we need to build a DarkRiftWriter to put the data we want to send in, it'll default to Unicode //encoding so we don't need to worry about that using (DarkRiftWriter writer = DarkRiftWriter.Create()) { //We can then write the input text into it writer.Write(input.text); //Next we construct a message, in this case we can just use a default tag because there is nothing fancy //that needs to happen before we read the data. using (Message message = Message.Create(0, writer)) { //Finally we send the message to everyone connected! client.SendMessage(message, SendMode.Reliable); } } }
void SerialisePosRot(Vector3 pos, Quaternion rot, ushort ID, bool isVarKinematic) { //Here is where we actually serialise things manually. To do this we need to add //any data we want to send to a DarkRiftWriter. and then send this as we would normally. //The advantage of custom serialisation is that you have a much smaller overhead than when //the default BinaryFormatter is used, typically about 50 bytes. using (DarkRiftWriter writer = new DarkRiftWriter()) { //Next we write any data to the writer writer.Write(isVarKinematic); writer.Write(pos.x); writer.Write(pos.y); writer.Write(pos.z); writer.Write(rot.x); writer.Write(rot.y); writer.Write(rot.z); writer.Write(rot.w); DarkRiftAPI.SendMessageToOthers(TagIndexVRTK.ObjectUpdate, ID, writer); if (DEBUG) { Debug.Log("Data sent: " + pos.ToString("F4") + " " + rot.ToString("F6")); } } }
public void StartGame() { var writer = new DarkRiftWriter(); writer.Write(Instance.CurrentRoom.Id); MainClient.Instance.SendMessage(new TagSubjectMessage(Tags.Room, RoomSubjects.StartGame, writer), SendMode.Reliable); }
public void OnCreateWorld(object sender, MessageReceivedEventArgs e) { using (Message message = e.GetMessage() as Message) { CreateWorldClientDTO data = message.GetReader().ReadSerializable <CreateWorldClientDTO>(); using (DarkRiftWriter responseWriter = DarkRiftWriter.Create()) { CreateWorldServerDTO response = new CreateWorldServerDTO(); if (GetWorldByName(data.WorldName) == null) { WorldData NewWorld = new WorldData(data.WorldName, data.SceneEntityID, data.SceneName); this.Worlds.Add(NewWorld); response.Success = true; response.Message = $"{data.WorldName} Created"; Console.WriteLine(response.Message); } else { response.Success = false; response.Message = $"{data.WorldName} already exists"; Console.WriteLine(response.Message); } responseWriter.Write(response); using (Message responseMessage = Message.Create(Tags.CreateWorldMessage, responseWriter)) e.Client.SendMessage(responseMessage, SendMode.Reliable); } } }
void SendServerList(MessageReceivedEventArgs e) { using (DarkRiftWriter writer = DarkRiftWriter.Create()) { writer.Write(rooms.Where(x => x.PublicServer).Count()); // Since we are using TCP for reliable, MTU isnt important. If you use a RUDP transport for DarkRift, make sure it has fragmentation or split the server list up into chunks of a few per packet. for (int i = 0; i < rooms.Count; i++) { if (rooms[i].PublicServer) { writer.Write(rooms[i].ServerName); writer.Write(rooms[i].Clients.Count + 1); writer.Write(rooms[i].MaxPlayers); writer.Write(rooms[i].Host.ID); writer.Write(rooms[i].ServerData); } } using (Message sendServerList = Message.Create((ushort)OpCodes.ServerListResponse, writer)) { e.Client.SendMessage(sendServerList, SendMode.Reliable); } } }
public void DespawnTurret() { for (var i = 0; i < turrets.Length; i++) { this.turrets[i].DespawnTurret(); } using (var writer = DarkRiftWriter.Create()) { for (ushort i = 0; i < turrets.Length; i++) { writer.Write(new TurretSpawnData { ID = 0, Index = i }); } using (var spawnMessage = Message.Create(MsgTags.TurretDespawn, writer)) { foreach (var client in this.server.ClientManager.GetAllClients()) { client.SendMessage(spawnMessage, SendMode.Reliable); } } } }
public void OnGetWorlds(object sender, MessageReceivedEventArgs e) { using (DarkRiftWriter responseWriter = DarkRiftWriter.Create()) { WorldDTO[] worldDtos = new WorldDTO[Worlds.Count]; for (int i = 0; i < Worlds.Count; i++) { WorldData world = Worlds[i]; WorldDTO worldDto = new WorldDTO(); worldDto.WorldName = world.WorldName; worldDto.NrPlayers = world.players.Count; worldDto.MaxNrPlayers = 0; worldDto.SceneName = world.SceneName; worldDto.SceneEntityID = world.SceneEntityID; worldDtos[i] = worldDto; } GetWorldsServerDTO response = new GetWorldsServerDTO(); response.Worlds = worldDtos; responseWriter.Write(response); using (Message responseMessage = Message.Create(Tags.GetWorldsMessage, responseWriter)) e.Client.SendMessage(responseMessage, SendMode.Reliable); } }
//Called when the object is dragged by the mouse void OnMouseDrag() { //Check we have a client to send from if (client == null) { Debug.LogError("No client assigned to DragObject!"); return; } //Firstly we need to work out where the object should be, we can ignore the z-coord returned Vector3 newPos = Camera.main.ScreenPointToRay(Input.mousePosition).GetPoint(10); //We want to send the new position of the object to the other clients so we write our ID and //our position (as x, y and z components) into a DarkRiftWriter using (DarkRiftWriter writer = DarkRiftWriter.Create()) { writer.Write(dragID); writer.Write(newPos.x); writer.Write(newPos.y); //Then we'll create a new message and put the DarkRiftWriter into it. //The tag indicates what the message is about so we'll put a tag of '0' to indicate a //movement. using (Message message = Message.Create(MOVE_TAG, writer)) { //We can then send the message client.SendMessage(message, SendMode.Unreliable); } } //Last but not least we'll actually move the object on our screen so set the target position to //the new position targetPosition = new Vector3(newPos.x, newPos.y, 0); }
public void TimerElapsed(object sender, ElapsedEventArgs args) { if (((Timer)sender).Equals(timerWhites)) { using (DarkRiftWriter messageWriter = DarkRiftWriter.Create()) { messageWriter.Write(true); using (Message tickMessage = Message.Create((ushort)ChessEnums.MessageTags.TimerTick, messageWriter)) { client1.SendMessage(tickMessage, SendMode.Unreliable); client2.SendMessage(tickMessage, SendMode.Unreliable); } } } else { using (DarkRiftWriter messageWriter = DarkRiftWriter.Create()) { messageWriter.Write(false); using (Message tickMessage = Message.Create((ushort)ChessEnums.MessageTags.TimerTick, messageWriter)) { client1.SendMessage(tickMessage, SendMode.Unreliable); client2.SendMessage(tickMessage, SendMode.Unreliable); } } } }
private void ClientDisconnected(object sender, ClientDisconnectedEventArgs e) { e.Client.MessageReceived -= SpawnObject; e.Client.MessageReceived -= SpawnObjectWithRot; e.Client.MessageReceived -= Movement; using (DarkRiftWriter writer = DarkRiftWriter.Create()) { foreach (ushort entID in clientEntitySetLookup[e.Client.ID]) { writer.Write(entID); entityCount--; freeID.Enqueue(entID); networkEntities.Remove(entID); } using (Message message = Message.Create(Tags.destroyObjectTag, writer)) { foreach (IClient client in ClientManager.GetAllClients()) { client.SendMessage(message, SendMode.Reliable); } } } clientEntitySetLookup.Remove(e.Client.ID); }
void SendLaserDirection() { if (PlayerCreator.connected == false) { return; } using (DarkRiftWriter writer = DarkRiftWriter.Create()) { GameObject redLaserGun = GameObject.Find("RedLaserGun"); GameObject blueLaserGun = GameObject.Find("BlueLaserGun"); writer.Write(redLaserGun.transform.rotation.x); writer.Write(redLaserGun.transform.rotation.y); writer.Write(redLaserGun.transform.rotation.z); writer.Write(redLaserGun.transform.rotation.w); writer.Write(blueLaserGun.transform.rotation.x); writer.Write(blueLaserGun.transform.rotation.y); writer.Write(blueLaserGun.transform.rotation.z); writer.Write(blueLaserGun.transform.rotation.w); using (Message message = Message.Create(Tags.ChangeLaserDirectionTag, writer)) { client.SendMessage(message, SendMode.Reliable); } } }
/// <summary> /// Here all the previously spawned entities are sent to the newly connected client and the IClient reference is added /// to the clients dictionary /// </summary> private void ClientConnected(object sender, ClientConnectedEventArgs e) { using (DarkRiftWriter writer = DarkRiftWriter.Create()) { foreach (ushort client in clientEntitySetLookup.Keys) { foreach (ushort entID in clientEntitySetLookup[client]) { NetworkEntity entity = GetNetworkEntity(entID); writer.Write(entity.owner); writer.Write(entity.id); writer.Write(entity.index); writer.Write(entity.posX); writer.Write(entity.posY); writer.Write(entity.posZ); writer.Write(entity.rotX); writer.Write(entity.rotY); writer.Write(entity.rotZ); } } if (writer.Length > 0) { using (Message m = Message.Create(Tags.spawnObjectWithRotTag, writer)) { e.Client.SendMessage(m, SendMode.Reliable); } } } clientEntitySetLookup.Add(e.Client.ID, new HashSet <ushort>()); e.Client.MessageReceived += SpawnObject; e.Client.MessageReceived += SpawnObjectWithRot; e.Client.MessageReceived += Movement; }
public void OnButtonPressed() { BuildingDecks.SetActive(true); using (DarkRiftWriter writer = new DarkRiftWriter()) { Manager.Connection.SendMessageToServer((byte)TagsNSubjects.Tags.CARDTAG, (ushort)TagsNSubjects.CardSubjects.AVAILABLECARDS, writer); } }
public void OnGetInventory(object sender, MessageReceivedEventArgs e) { using (Message message = e.GetMessage() as Message) { GetInventoryClientDTO data = message.GetReader().ReadSerializable <GetInventoryClientDTO>(); using (DarkRiftWriter responseWriter = DarkRiftWriter.Create()) { InventoryDTO invData = null;/*db.Inventories * .Where((x) => x.Id == data.InventoryID) * .FirstOrDefault();*/ if (invData != null) { InventoryItemDTO[] inventoryItems = null; /* db.InventoryItems * .Where((x) => x._inventoryid == data.InventoryID) * .ToArray();*/ GetInventoryServerDTO response = new GetInventoryServerDTO(); response.InventoryID = invData.Id; response.Size = invData.Size; response.InventoryItems = inventoryItems; responseWriter.Write(response); using (Message responseMessage = Message.Create(Tags.GetInventory, responseWriter)) e.Client.SendMessage(responseMessage, SendMode.Reliable); } return; //terminate } } }
void ClientDisconnected(object sender, ClientDisconnectedEventArgs e) { players.Remove(e.Client); using (DarkRiftWriter writer = DarkRiftWriter.Create()) { writer.Write(e.Client.ID); using (Message message = Message.Create(DESPAWN_TAG, writer)) { foreach (IClient client in ClientManager.GetAllClients()) { client.SendMessage(message, SendMode.Reliable); } } } if (players.Count == 0) { testTrain = null; objects.Clear(); IDCounter = 0; InitializeTrain(); InitializeObjects(); gameStarted = false; } }
void CreateRoom(MessageReceivedEventArgs e, int maxPlayers = 10, string serverName = "My Server", bool isPublic = true, string serverData = "", bool forceRelay = false, string localIP = "127.0.0.1") { LeaveRoom(e.Client); lock (rooms) { Room room = new Room { Host = e.Client, MaxPlayers = maxPlayers, Clients = new List <IClient>(), ServerName = serverName, PublicServer = isPublic, ServerData = serverData, ForceRelay = forceRelay, ServerLocalIP = localIP }; rooms.Add(room); // Tell the client that the room was created. using (DarkRiftWriter writer = DarkRiftWriter.Create()) { writer.Write(e.Client.ID); using (Message sendCreatedMessage = Message.Create((ushort)OpCodes.RoomCreated, writer)) { e.Client.SendMessage(sendCreatedMessage, SendMode.Reliable); } } } }
public void FinalizeJoinRequest(string matchmakerTicket, UserAccountInfo userInfo, bool approved) { IClient client = tempTicketMap[matchmakerTicket]; tempTicketMap.Remove(matchmakerTicket); //Respond to client with approval status using (DarkRiftWriter writer = DarkRiftWriter.Create()) { writer.Write(approved); using (Message message = Message.Create(NetworkTags.Connection, writer)) { client.SendMessage(message, SendMode.Reliable); } } //Record client in lobby map if (LobbyClientAccountMap.ContainsKey(client)) { LobbyClientAccountMap[client] = userInfo; } else { LobbyClientAccountMap.Add(client, userInfo); } }
public Message GenerateSpawnMessage() { var list = PrepareSpawnPositions(); using (DarkRiftWriter writer = DarkRiftWriter.Create()) { foreach (PlayerSpawnData spawnData in list) { //ID writer.Write(spawnData.Id); //Position writer.Write(spawnData.X); writer.Write(spawnData.Y); //Item count followed by item Id's var itemCount = (short)spawnData.ItemIds.Count; writer.Write(itemCount); foreach (var data in spawnData.ItemIds) { writer.Write(data); } //Module count followed by module Id's var moduleCount = (short)spawnData.WeaponModuleIds.Count; writer.Write(moduleCount); foreach (var data in spawnData.WeaponModuleIds) { writer.Write(data); } } return(Message.Create(Tags.SpawnCharacter, writer)); } }
public void OnButtonPressed() { foreach (GameObject go in Lobbymanager.Instance.DeckList) { Lobbymanager.Instance.Deck.Add(go.GetComponent <ListObject> ().cardId); } if (Lobbymanager.Instance.Deck.Count != Globalmanager.deckSize) { Lobbymanager.Instance.Deck.Clear(); Error.Instance.PopUp("The Deck Size shold be" + Globalmanager.deckSize.ToString()); return; } BuildingDecks.SetActive(false); //schliesst das Fenster wieder, macht es unsichtbar using (DarkRiftWriter writer = new DarkRiftWriter()) { foreach (ushort card in Lobbymanager.Instance.Deck) { writer.Write(card); } if (deckNumber == 1) { Manager.Connection.SendMessageToServer((byte)TagsNSubjects.Tags.CARDTAG, (ushort)TagsNSubjects.CardSubjects.Deck1Built, writer); } if (deckNumber == 2) { Manager.Connection.SendMessageToServer((byte)TagsNSubjects.Tags.CARDTAG, (ushort)TagsNSubjects.CardSubjects.Deck2Built, writer); } } }
public static DarkRiftReader DecryptReaderRSA(this DarkRiftReader reader, RSAParameters privateKey) { if (reader.Length > 256) { throw new ArgumentOutOfRangeException(nameof(reader), "reader mustn't contain more then 256 bytes"); } byte[] data = new byte[256]; for (int i = 0; i < 256; i++) { data[i] = reader.ReadByte(); } data = DecryptRSA(data, privateKey); DarkRiftWriter writer = DarkRiftWriter.Create(); writer.WriteRaw(data, 0, data.Length); Message message = Message.Create(0, writer); DarkRiftReader newReader = message.GetReader(); message.Dispose(); writer.Dispose(); reader.Dispose(); return(newReader); }
//Called when the object is dragged by the mouse void OnMouseDrag() { //Check we have a client to send from if (client == null) { Debug.LogError("No client assigned to DragObject!"); return; } //Firstly we need to work out where the object should be, we can ignore the z-coord returned Vector3 newPos = Camera.main.ScreenPointToRay(Input.mousePosition).GetPoint(10); //We want to send the new position of the object to the other clients so we write the position //into a DarkRiftWriter as x, y and z components DarkRiftWriter writer = new DarkRiftWriter(); writer.Write(newPos.x); writer.Write(newPos.y); //Then we'll create a new TagSubject message and put the DarkRiftWriter into it. //The tag and subject indicate what the message is about so we'll put a tag of '0' to indicate a //movement and set the subject to the ID of this object so that we can easily identify it later. Message message = new TagSubjectMessage(dragID, 0, writer); //We can then send the message client.SendMessage(message, SendMode.Unreliable); //TODO 1 will this be a problem without others as an intention? //Last but not least we'll actually move the object on our screen so set the target position to //the new position targetPosition = new Vector3(newPos.x, newPos.y, 0); }
void SerialisePos(Vector3 pos) { //Here is where we actually serialise things manually. To do this we need to add //any data we want to send to a DarkRiftWriter. and then send this as we would normally. //The advantage of custom serialisation is that you have a much smaller overhead than when //the default BinaryFormatter is used, typically about 50 bytes. using(DarkRiftWriter writer = new DarkRiftWriter()) { //Next we write any data to the writer, as we never change the z pos there's no need to //send it. writer.Write(pos.x); writer.Write(pos.y); DarkRiftAPI.SendMessageToOthers(0, (ushort)cubeID, writer); } }
/// <summary> /// Logs out the user from the server. /// </summary> public static void Logout() { //Build the data to send using(DarkRiftWriter writer = new DarkRiftWriter()) { writer.Write(0); //Choose the connection to use if( connection == null ) { if( DarkRiftAPI.isConnected ) { //Send via DarkRiftAPI DarkRiftAPI.SendMessageToServer( tag, logoutSubject, writer ); BindIfNotBound(); } else { //Called if you try to login whilst not connected to a server Debug.LogError("[LoginPlugin] You can't logout if you're not connected to a server! (Do you mean to use DarkRiftAPI?)"); } } else { if( connection.isConnected ) { //Send via DarkRiftConnection connection.SendMessageToServer( tag, logoutSubject, writer ); BindIfNotBound(); } else { //Called if you try to login whilst not connected to a server Debug.LogError("[LoginPlugin] You can't logout if you're not connected to a server!"); } } } }
/// <summary> /// Login with the specified username and password. /// </summary> /// <param name="username">The username.</param> /// <param name="password">The password.</param> public static void Login(string username, string password) { //Stop people from simply spamming the server if (string.IsNullOrEmpty (username) || string.IsNullOrEmpty (password)) return; //Build the data to send using( DarkRiftWriter writer = new DarkRiftWriter() ) { writer.Write(username); writer.Write(SecurityHelper.GetHash(password, hashType)); //Choose the connection to use if( connection == null ) { if( DarkRiftAPI.isConnected ) { //Send via DarkRiftAPI DarkRiftAPI.SendMessageToServer( tag, loginSubject, writer ); BindIfNotBound(); } else { //Called if you try to login whilst not connected to a server Debug.LogError("[LoginPlugin] You can't login if you're not connected to a server! (Do you mean to use DarkRiftAPI?)"); } } else { if( connection.isConnected ) { //Send via DarkRiftConnection connection.SendMessageToServer( tag, loginSubject, writer ); BindIfNotBound(); } else { //Called if you try to login whilst not connected to a server Debug.LogError("[LoginPlugin] You can't login if you're not connected to a server!"); } } } }