public void RegisterAccessorCannotConvertAccessorTypeException() { Assert.Throws <ArgumentException>(() => ProtocolBuilder .Create <int>() // Only "Implementing" Byte .RegisterAccessor(typeof(Int32), typeof(NullAccessor))); }
public void WriteField() { var def = ProtocolBuilder .Create <int>() .RegisterDefaultAccessors() .RegisterPacket((a) => a .Id(0x00) .BindingType <SamplePacket>() .BindField(nameof(SamplePacket.Field)) ).Build(new ExpressionDelegateBuilder()); var packetDef = def.Packets.First(); var vals = new byte[1]; rnd.NextBytes(vals); var val = vals[0]; using (var stream = new MemoryStream()) { var packet = new SamplePacket() { Field = val, }; packetDef.WriteDelegate(stream, packet); stream.Position = 0; Assert.AreEqual(val, (byte)stream.ReadByte()); } }
public void RegisterAccessorInvalidAccessorTypeException() { Assert.Throws <ArgumentException>(() => ProtocolBuilder .Create <int>() // Clearly not implementing INetworkAccessor .RegisterAccessor(typeof(Byte), typeof(Byte))); }
public void RegisterAccessorAccessorNullException() { Assert.Throws <ArgumentNullException>(() => ProtocolBuilder .Create <int>() .RegisterAccessor(typeof(Byte), null)); }
public RemoteTunnel(ConnectionBuilder cbuilder, ProtocolBuilder pfactory, int maxConnections = 2, int throttle = 0) : this(maxConnections) { CreateConnection = cbuilder; CreateProtocol = pfactory; Throttle = throttle; }
public void SavePlayerPosition(string charname, string x, string y, string z, int clientId) { string RetVar = ""; pBuilder = new ProtocolBuilder("SavePlayerPosition"); pBuilder.Add(charname); pBuilder.Add(x); pBuilder.Add(y); pBuilder.Add(z, true); using (TesteunityEntities contexto = new TesteunityEntities()) { //Verifica se já existe o username no BD var queryPlayer = (from p in contexto.Players where p.Nome == charname select p).SingleOrDefault(); Player player = new Player(); player = queryPlayer; player.PosX = Convert.ToDouble(x); player.PosY = Convert.ToDouble(y); player.PosZ = Convert.ToDouble(z); contexto.SaveChanges(); } Server._sProtocolResponse = RetVar; }
public void ReadProperty() { var def = ProtocolBuilder .Create <int>() .RegisterDefaultAccessors() .RegisterPacket((a) => a .Id(0x00) .BindingType <SamplePacket>() .BindProperty(nameof(SamplePacket.Property)) ).Build(new ExpressionDelegateBuilder()); var packetDef = def.Packets.First(); var vals = new byte[1]; rnd.NextBytes(vals); var val = vals[0]; using (var stream = new MemoryStream(new byte[] { val })) { var readPacket = (SamplePacket)packetDef.ReadDelegate(stream); Assert.NotNull(readPacket); Assert.AreEqual(val, readPacket.Property); } }
public void AddPacket() { Assert.True(ProtocolBuilder .Create <int>() .RegisterPacket((a) => { }) .Build(nullBuilder).Packets.Length == 1); }
public void RegisterLogin(string userParam, string PwdParam, string emailParam, string firsLogin, int clientId) { string RetVar = ""; pBuilder = new ProtocolBuilder("RegisterLogin"); pBuilder.Add(userParam); pBuilder.Add(PwdParam); pBuilder.Add(emailParam); pBuilder.Add(firsLogin, true); using (TesteunityEntities contexto = new TesteunityEntities()) { //Verifica se já existe o username no BD var queryUserName = (from u in contexto.Users where u.nome == userParam select u).ToList(); var queryEmail = (from u in contexto.Users where u.email == emailParam select u).ToList(); if (queryUserName.Count == 0) { if (queryEmail.Count == 0) { User user = new User(); user.nome = userParam; user.senha = PwdParam; user.email = emailParam; if (firsLogin == "1") { user.primeirologin = true; } try { contexto.Users.Add(user); contexto.SaveChanges(); RetVar = "[Regok]"; //Cadastro realizado com sucesso! } catch (Exception e) { RetVar = "[Regnotsaved]"; //User not saved, try again later! } } else { RetVar = "[Regemailexistent]"; //E-mail já utilizado, tente cadastrar outro } } else { RetVar = "[Regnameexistent]"; //Username já existe, tente cadastrar outro! } } Server._sProtocolResponse = RetVar; }
public void IdWrongTypeException() { Assert.Throws <ArgumentException>(() => ProtocolBuilder .Create <int>() .RegisterPacket((a) => a .Id("this is the wrong type"))); }
public void SetBindingTypeBeforePropertyBinding() { Assert.Throws <InvalidOperationException>(() => ProtocolBuilder .Create <int>() .RegisterPacket((a) => a .BindProperty(nameof(SamplePacket.Field)))); }
public void BindingTypeNullException() { Assert.Throws <ArgumentNullException>(() => ProtocolBuilder .Create <int>() .RegisterPacket((a) => a .BindingType(null))); }
public void IdSaved() { int Id = rnd.Next(); Assert.AreEqual(Id, ProtocolBuilder .Create <int>() .RegisterPacket((a) => a .Id(Id)).Build(nullBuilder).Packets.First().Id); }
public void PropertyBindingFieldException() { Assert.Throws <ArgumentException>(() => ProtocolBuilder .Create <int>() .RegisterPacket((a) => a .Id(0) .BindingType <SamplePacket>() .BindProperty(nameof(SamplePacket.Field)) )); }
public void BindingType() { var def = ProtocolBuilder .Create <int>() .RegisterPacket((a) => a .Id(0) .BindingType <SamplePacket>() ).Build(nullBuilder); Assert.True(def.Packets.First().Binding == typeof(SamplePacket)); }
public void UnknownTag(int clientId) { string RetVar = ""; pBuilder = new ProtocolBuilder("UnknTag"); RetVar = "Protocolo desconhecido"; Server._sProtocolResponse = RetVar; }
public void PropertyBinding() { var def = ProtocolBuilder .Create <int>() .RegisterPacket((a) => a .Id(0) .BindingType <SamplePacket>() .BindProperty(nameof(SamplePacket.Property)) ).Build(nullBuilder); Assert.True(def.Packets.First().Bindings.Length == 1, "Wrong Length"); Assert.True(def.Packets.First().Bindings.First() == typeof(SamplePacket).GetProperty(nameof(SamplePacket.Property)), "Binding Type Wrong"); }
public static ProtocolDefinition GetNetworkDefinition() => ProtocolBuilder .Create <int>() .LengthBehaviour(new DefaultDynamicInt32LengthBehaviour()) .UseIds(new DefaultIdHeader(), new DelegateIdMapper((id, protocol) => protocol.Packets.First(x => ((int)x.Id) == (int)id), (def, protocol) => def.Id)) .RegisterDefaultAccessors() .RegisterPacket((a) => a .Id(0x00) .BindingType <SingleByteTransferPacket>() .BindField(nameof(SingleByteTransferPacket.Data)) ).Build(new ExpressionDelegateBuilder());
public void RequestPlayerDetails(string playerName, string nada, int clientId) { string RetVar = ""; pBuilder = new ProtocolBuilder("RequestPlayerDetails"); pBuilder.Add(playerName); pBuilder.Add(nada, true); using (TesteunityEntities contexto = new TesteunityEntities()) { //StringBuilder sb = new StringBuilder(); string details; //Verifica se já existe o username no BD var queryPlayer = (from p in contexto.Players where (p.Nome == playerName) select p).SingleOrDefault(); details = queryPlayer.Nome + "|" + queryPlayer.Sexo + "|" + queryPlayer.Nivel.ToString() + "|" + queryPlayer.Vida.ToString() + "|" + queryPlayer.Mana.ToString() + "|" + queryPlayer.PosX.ToString() + "|" + queryPlayer.PosY.ToString() + "|" + queryPlayer.PosZ.ToString() + "|" + queryPlayer.valorvermelhopelemasc.ToString() + "|" + queryPlayer.valorverdepelemasc.ToString() + "|" + queryPlayer.valorazulpelemasc.ToString() + "|" + queryPlayer.valorvermelhocabelomasc.ToString() + "|" + queryPlayer.valorverdecabelomasc + "|" + queryPlayer.valorazulcabelomasc + "|" + queryPlayer.valorvermelhoblusamasc + "|" + queryPlayer.valorverdeblusamasc + "|" + queryPlayer.valorazulblusamasc + "|" + queryPlayer.valorvermelhocalcamasc + "|" + queryPlayer.valorverdecalcamasc + "|" + queryPlayer.valorazulcalcamasc; RetVar = "[Chardetails]" + details; //detalhes } Server._sProtocolResponse = RetVar; }
public void RequestListOfPlayers(string userNameParam, string nada, int clientId) { string RetVar = ""; pBuilder = new ProtocolBuilder("RequestListOfPlayers"); pBuilder.Add(userNameParam); pBuilder.Add(nada, true); using (TesteunityEntities contexto = new TesteunityEntities()) { StringBuilder sb = new StringBuilder(); //Verifica se já existe o username no BD var queryuserName = (from u in contexto.Users where (u.nome == userNameParam) select u).SingleOrDefault(); var queryPlayers = (from p in contexto.Players where (p.ID_USER_PLAYERS == queryuserName.ID) select p).ToList(); foreach (var p in queryPlayers) { if (queryPlayers.IndexOf(p) == queryPlayers.Count - 1) { sb.Append(p.Nome); } else { sb.Append(p.Nome); sb.Append("|"); } } if (queryPlayers.Count == 0) { RetVar = "[Charsinexistents]"; //no players registered for this account } else { RetVar = "[Charsexistents]" + sb.ToString(); //Players registered! } } Server._sProtocolResponse = RetVar; }
public RemoteTunnel(string url, DataEncoding encoding = DataEncoding.Proto, int maxConnections = 2) : this(maxConnections) { if (url == null) throw new ArgumentNullException(); EndPoint = new Uri(url); var throttle = 0; CreateConnection = ConnectionBuilderFromUri(EndPoint, out throttle); Throttle = throttle; switch (encoding) { case DataEncoding.Memcached: CreateProtocol = (dtc) => { return new Memcached.ClientProtocol(dtc); }; break; default: throw new NotImplementedException(encoding.ToString()); } }
public void LoginMember(string userParam, string PwdParam, string firstlogin, int clientId) { string RetVar = ""; pBuilder = new ProtocolBuilder("LoginMemb"); pBuilder.Add(userParam); pBuilder.Add(PwdParam); pBuilder.Add(firstlogin, true); using (TesteunityEntities contexto = new TesteunityEntities()) { //Verifica se já existe o username no BD var query = (from u in contexto.Users where (u.nome == userParam) && (u.senha == PwdParam) select u).SingleOrDefault(); if (query != null) { if (query.senha != PwdParam) { RetVar = "[Loginfail]"; //Login failed! } else { if (query.primeirologin == true) { RetVar = "[Loginok1]"; //Login ok! Welcome to your first time here. query.primeirologin = false; contexto.SaveChanges(); } else { RetVar = "[Loginok]"; //Login ok! } } } else { RetVar = "[Loginfail]"; //Login failed! } } Server._sProtocolResponse = RetVar; }
public void CreateGeneric() { Assert.AreEqual(typeof(Int32), ProtocolBuilder.Create <Int32>().Build(nullBuilder).IdType); }
public void CreateCharacter(string nameUser, string namePlayer, string genre, string level, string life, string mana, string posx, string posy, string posz, string sredvalueskintmale, string sgreenvalueskinmale, string sbluevalueskinmale, string sredvaluehairtmale, string sgreenvaluehairtmale, string sbluevaluehairtmale, string sredvalueshirtmale, string sgreenvalueshirtmale, string sbluevalueshirtmale, string sredvaluepantsmale, string sgreenvaluepantsmale, string sbluevaluepantsmale, int clientId) { string RetVar = ""; pBuilder = new ProtocolBuilder("CreateCharacter"); pBuilder.Add(nameUser); pBuilder.Add(namePlayer); pBuilder.Add(genre); pBuilder.Add(life); pBuilder.Add(mana); pBuilder.Add(posx); pBuilder.Add(posy); pBuilder.Add(posz); pBuilder.Add(sredvalueskintmale); pBuilder.Add(sgreenvalueskinmale); pBuilder.Add(sbluevalueskinmale); pBuilder.Add(sredvaluehairtmale); pBuilder.Add(sgreenvaluehairtmale); pBuilder.Add(sbluevaluehairtmale); pBuilder.Add(sredvalueshirtmale); pBuilder.Add(sgreenvalueshirtmale); pBuilder.Add(sbluevalueshirtmale); pBuilder.Add(sredvaluepantsmale); pBuilder.Add(sgreenvaluepantsmale); pBuilder.Add(sbluevaluepantsmale, true); using (TesteunityEntities contexto = new TesteunityEntities()) { var queryUserName = (from u in contexto.Users where u.nome == nameUser select u).SingleOrDefault(); var queryNamePlayer = (from p in contexto.Players where p.Nome == namePlayer select p).SingleOrDefault(); if (queryNamePlayer != null) { RetVar = "[Charnameexistent]"; //Name already chosen, try another one! } else { if (queryUserName != null) { Player player = new Player(); player.ID_USER_PLAYERS = queryUserName.ID; player.Nome = namePlayer; player.Sexo = genre; player.Nivel = Convert.ToInt32(level); player.Vida = Convert.ToDouble(life); player.Mana = Convert.ToDouble(mana); player.PosX = Convert.ToDouble(posx); player.PosY = Convert.ToDouble(posy); player.PosZ = Convert.ToDouble(posz); player.valorvermelhopelemasc = Convert.ToInt32(sredvalueskintmale); player.valorverdepelemasc = Convert.ToInt32(sgreenvalueskinmale); player.valorazulpelemasc = Convert.ToInt32(sbluevalueskinmale); player.valorvermelhocabelomasc = Convert.ToInt32(sredvaluehairtmale); player.valorverdecabelomasc = Convert.ToInt32(sgreenvaluehairtmale); player.valorazulcabelomasc = Convert.ToInt32(sbluevaluehairtmale); player.valorvermelhoblusamasc = Convert.ToDouble(sredvalueshirtmale); player.valorverdeblusamasc = Convert.ToDouble(sgreenvalueshirtmale); player.valorazulblusamasc = Convert.ToDouble(sbluevalueshirtmale); player.valorvermelhocalcamasc = Convert.ToDouble(sredvaluepantsmale); player.valorverdecalcamasc = Convert.ToDouble(sgreenvaluepantsmale); player.valorazulcalcamasc = Convert.ToDouble(sbluevaluepantsmale); try { contexto.Players.Add(player); contexto.SaveChanges(); RetVar = "[Charsaved]"; //Character Saved! } catch (Exception) { RetVar = "[Charnotsaved]"; } } } } Server._sProtocolResponse = RetVar; }
public void IdTypeNullException() { Assert.Throws <ArgumentNullException>(() => ProtocolBuilder.Create(null)); }
public static ProtocolBuilder RegisterDefaultAccessors(this ProtocolBuilder builder) => builder.RegisterAccessor <Byte, ByteAccessor>() .RegisterAccessor <Int32, Int32Accessor>() ;
public void CreateExplicit() { Assert.AreEqual(typeof(Int32), ProtocolBuilder.Create(typeof(Int32)).Build(nullBuilder).IdType); }