/// <summary>Test stub for LogIn(String, String, Byte[])</summary> public void LogInTest( TestClient client, string user, string pass, byte[] key ) { client.LogInAndConnect(user, pass, key); // If username not recognised, expect to be disconnected if (string.IsNullOrEmpty(user) || !Utility_Methods.CheckStringValid("combined", user) || !LogInManager.users.ContainsKey(user)) { Assert.AreEqual("Disconnected", client.net.GetConnectionStatusString()); return; } // If password is incorrect, expect an error Tuple <byte[], byte[]> hashNsalt = LogInManager.users[user]; byte[] hash; if (pass == null) { hash = null; } else { hash = LogInManager.ComputeHash(System.Text.Encoding.UTF8.GetBytes(pass), hashNsalt.Item2); } if (hash == null || !hashNsalt.Item1.SequenceEqual(hash) || key == null || key.Length < 5) { Assert.AreEqual("Disconnected", client.net.GetConnectionStatusString()); Assert.IsFalse(Server.ContainsConnection(user)); } else { // If the login was successful, expecting a ProtoLogin followed by a ProtoClient back Task <ProtoMessage> getReply = client.GetReply(); getReply.Wait(); ProtoMessage reply = getReply.Result; Assert.AreEqual(reply.GetType(), typeof(ProtoLogIn)); while (!client.IsConnectedAndLoggedIn()) { Thread.Sleep(0); } // If login was successful, the client should be in the list of registered observers Assert.IsTrue(Globals_Game.IsObserver(Globals_Server.Clients[user])); Assert.IsTrue(Server.ContainsConnection(user)); } }
public void Send(ProtoMessage message, bool encrypt = true) { NetOutgoingMessage msg = client.CreateMessage(); MemoryStream ms = new MemoryStream(); try { //Serializer.SerializeWithLengthPrefix<ProtoMessage>(ms, message, ProtoBuf.PrefixStyle.Fixed32); Console.Write("Client: Sending"); msg.Write(ms.GetBuffer()); if (alg != null && encrypt) { Console.Write(" encrypted"); msg.Encrypt(alg); } var result = client.SendMessage(msg, NetDeliveryMethod.ReliableOrdered); Console.WriteLine(" message of type " + message.GetType() + " with Action: " + message.ActionType + " with result: " + result.ToString()); client.FlushSendQueue(); } catch (Exception e) { Console.WriteLine("CLIENT: Failed to serialise message!"); } }
/// <summary>Test stub for AdjustExpenditure(String, Double, Double, Double, Double, Double)</summary> public void AdjustExpenditureTest( TestClient TestClient, string fiefID, double newTax, double newOff, double newGarr, double newKeep, double newInfra ) { TestClient.AdjustExpenditure(fiefID, newTax, newOff, newGarr, newKeep, newInfra); Client client = null; if (!ValidClientState(TestClient, out client)) { Task <string> ReplyTask = TestClient.GetServerMessage(); ReplyTask.Wait(); string reply = ReplyTask.Result; Assert.AreEqual("Not logged in- Disconnecting", reply); return; } // If not a valid fief, expect to fail if (string.IsNullOrWhiteSpace(fiefID) || !Globals_Game.fiefKeys.Contains(fiefID)) { Console.Write("not a fief Id "); Task <ProtoMessage> ReplyTask = TestClient.GetReply(); ReplyTask.Wait(); ProtoMessage reply = ReplyTask.Result; Assert.AreEqual(reply.ResponseType, DisplayMessages.ErrorGenericFiefUnidentified); } else { Task <ProtoMessage> ReplyTask = TestClient.GetReply(); ReplyTask.Wait(); ProtoMessage reply = ReplyTask.Result; // If not fief owner expect unauthorised Fief fief = null; Globals_Game.fiefMasterList.TryGetValue(fiefID, out fief); if (fief.owner != client.myPlayerCharacter) { Assert.AreEqual(reply.ResponseType, DisplayMessages.ErrorGenericUnauthorised); } // If numbers invalid expect an invalid exception else if (newTax < 0 || newOff < 0 || newGarr < 0 || newKeep < 0 || newInfra < 0) { Assert.AreEqual(reply.ResponseType, DisplayMessages.ErrorGenericMessageInvalid); } else { if (reply.GetType() == typeof(ProtoFief)) { Assert.AreEqual(DisplayMessages.FiefExpenditureAdjusted, reply.ResponseType); } else { Assert.AreEqual(DisplayMessages.FiefExpenditureAdjustment, reply.ResponseType); } } } }