/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Here we go. Let's define the functions that get called whenever a skill is executed. * This is the place where you wanna start to create your own custom skills. Perhaps some * kind of scripting support will be added in the far future. * */ public static void SkillRequest(int skillID, Database.Player.RACE race, Database.Player pAttacker, int targetID = 0, Map.Nod position = null) { Skill skill = null; Dictionary <int, Skill> dict = null; ActiveSkill activeSkill; if (!pAttacker.activeSkillList.TryGetValue(skillID, out activeSkill)) { throw new KeyNotFoundException(); } try { switch (race) { case Database.Player.RACE.KNIGHT: dict = knightSkillList; break; case Database.Player.RACE.MAGE: dict = mageSkillList; break; case Database.Player.RACE.ARCHER: dict = archerSkillList; break; default: throw new NullReferenceException(); break; } skill = dict[skillID]; } catch (KeyNotFoundException e) { Output.WriteLine("SkillHandler::GetSkillExecuteHandler " + "Someone tried to execute a skill for that no handler exists. " + e.Source.ToString() + " : " + e.TargetSite.ToString()); } catch (NullReferenceException) { // Should never ever happen -.- Output.WriteLine("SkillHandler::GetSkillExecuteHandler " + "Someone tried to request a skill for an unknown race!"); } //This is place where we do actions for requested skill Output.WriteLine("SkillRequest: " + skill.name); if (activeSkill.ElapsedCoolDown() > 0 && activeSkill.ElapsedCoolDown() < skill.coolDown) { Output.WriteLine(ConsoleColor.Red, "SkillHandler::SkillRequest - can't cast skill (still on CoolDown)"); Output.WriteLine(ConsoleColor.Red, "SkillHandler::SkillRequest CoolDown: " + activeSkill.ElapsedCoolDown().ToString()); return; } Output.WriteLine(ConsoleColor.DarkGreen, "SkillHandler::SkillRequest CoolDown: " + activeSkill.ElapsedCoolDown().ToString()); pAttacker.isCastingSkill = true; pAttacker.currentCastingSkillID = skillID; activeSkill.StartCast(); BroadcastPacket bPacket = new BroadcastPacket((uint)pAttacker.PosX, (uint)pAttacker.PosY, (int)World.DEBUG_SIGHT_RANGE, new Packet.SendPacketHandlers.SkillAnim(pAttacker.PlayerPID, targetID, activeSkill.skillID, activeSkill.skillLvl)); GameServer.world.broadcastQueue.Enqueue(bPacket); }
public static void LightningSkillRequest(Database.Player pAttacker, int targetID) { Output.WriteLine("SkillHandler::LightningSkillRequest"); BroadcastPacket bPacket = new BroadcastPacket((uint)pAttacker.PosX, (uint)pAttacker.PosY, (int)World.DEBUG_SIGHT_RANGE, new Packet.SendPacketHandlers.SkillAnim(pAttacker.PlayerPID, targetID, 2, 2)); GameServer.world.broadcastQueue.Enqueue(bPacket); //Monster attackedMob = World.Monsters[mobID]; //attackedMob.broadcastPacket(new PlayAnimation(mobID, pAttacker.UniqueID, 4)); }
public static void LightningSkillExecute(Database.Player pAttacker, int targetID) { Output.WriteLine("SkillHandler::LightningSkillExecute"); //GameServer.world.BroadcastPacket(pConn.client.GetPlayer(), new Packet.SendPacketHandlers.AttackMag(casterID, targetID, skill_id, skill_lvl)); BroadcastPacket bPacket = new BroadcastPacket((uint)pAttacker.PosX, (uint)pAttacker.PosY, (int)World.DEBUG_SIGHT_RANGE, new Packet.SendPacketHandlers.AttackMag(pAttacker.PlayerPID, targetID, 2, 2)); GameServer.world.broadcastQueue.Enqueue(bPacket); //Monster attackedMob = World.Monsters[mobID]; //Packet attackPacket = new ExecuteSkill(pAttacker.UniqueID, attackedMob.UniqueID, 4, 1, 1, 31, 0); //attackedMob.broadcastPacket(attackPacket); //attackedMob.getDamage((ushort)Server.rand.Next(100), pAttacker); }
public static void BeheadSkillExecute(Database.Player pAttacker, int targetID) { Output.WriteLine("SkillHandler::BeheadSkillExecute"); //Database.Mob attackedMob = World.Monsters[mobID]; //Packet attackPacket = new ExecuteSkill(pAttacker.UniqueID, attackedMob.UniqueID, 1, 1, 0, 0, 0); //attackedMob.broadcastPacket(attackPacket); //Packet aniPack = new PlayAnimation(mobID, 10); //attackedMob.broadcastPacket(aniPack); //attackedMob.OnBehead(pAttacker); }
//User select character to delete public static void CharacterDelete(Connection pConn, byte[] data) { if (Program.DEBUG_recv_stage1 || Program.DEBUG_recv) { Output.WriteLine("RecvPacketHandlers::CharacterDelete Recv delete char packet"); } if (pConn.client.Status != Client.STATUS.CharSelect) { if (Program.DEBUG_recv) { Output.WriteLine("RecvPacketHandlers::CharacterDelete - Error recv CharacterDelete beafore login, close connection"); } pConn.Close(); return; } int playerID = BitConverter.ToInt32(data, Program.receivePrefixLength); Database.Player p = pConn.client.GetPlayer(playerID); if (p == null) { if (Program.DEBUG_recv) { Output.WriteLine("RecvPacketHandlers::CharacterDelete Selected non existing player!"); } pConn.Close(); return; } else { //delete char from DB //send to client confirmation about succes in deletion bool fStatus = Database.DB_Acces.DeletePlayer(pConn.client.UserID, playerID); if (fStatus) { if (Program.DEBUG_recv) { Output.WriteLine("RecvPacketHandlers::CharacterDelete player: " + p.PlayerName + " was seccesfully deleted"); } pConn.client.DeletePlayer(p); pConn.Send(new SendPacketHandlers.OperationStatus((int)SendPacketHandlers.OPERATION_TYPE.CHARACTER_DELETE, (int)SendPacketHandlers.OPERATION_STATUS.SUCCES)); } else { if (Program.DEBUG_recv) { Output.WriteLine("RecvPacketHandlers::CharacterDelete player: " + p.PlayerName + " ERROR deleting from DB"); } pConn.Send(new SendPacketHandlers.OperationStatus((int)SendPacketHandlers.OPERATION_TYPE.CHARACTER_DELETE, (int)SendPacketHandlers.OPERATION_STATUS.FAIL)); } } }
public ActionResult AddPlayer(Database.Player player) { if (player.Name == null) { return(View("ErrorData")); } using (Database.MagicPortalContext context = new Database.MagicPortalContext()) { if (context.Players.Find(player.Name) != null) { return(View("ErrorData")); } player.EnlistDate = DateTime.Now; context.Set <Database.Player>().Add(player); context.SaveChanges(); var players = context.Players.ToList(); return(View("Players", players)); } }
//Check if requested skill is in current player skill list public static OnSkillExecute GetSkillExecuteHandler(int skillID, Database.Player player) { try { ActiveSkill ask; Dictionary <int, Skill> dict = null; if (!player.activeSkillList.TryGetValue(skillID, out ask)) { throw new KeyNotFoundException(); } switch ((Database.Player.RACE)player.Race) { case Database.Player.RACE.KNIGHT: dict = knightSkillList; break; case Database.Player.RACE.MAGE: dict = mageSkillList; break; case Database.Player.RACE.ARCHER: dict = archerSkillList; break; default: throw new NullReferenceException(); break; } OnSkillExecute executeHandler = dict[skillID].Execute; return(executeHandler); } catch (KeyNotFoundException e) { Output.WriteLine("SkillHandler::GetSkillExecuteHandler " + "Someone tried to execute a skill for that no handler exists. " + e.Source.ToString() + " : " + e.TargetSite.ToString()); } catch (NullReferenceException) { // Should never ever happen -.- Output.WriteLine("SkillHandler::GetSkillExecuteHandler " + "Someone tried to request a skill for an unknown race!"); } return(null); }
public Credential(Database.Player playedEntity) { email = playedEntity.Email; password = playedEntity.Password; }
public SetQuestPacket(QuestListPacket.QuestDefiniton questdef, Database.Player p) { this.questdef = questdef; this.p = p; }
public SetQuestPacket(QuestDefiniton questdef, Database.Player p) { this.questdef = questdef; this.p = p; }
// // OLD WAY TO CALL SKILLS // // public static void BeheadSkillRequest(Database.Player pAttacker, int targetID) { // no implementation here :) Output.WriteLine("SkillHandler::BeheadSkillRequest"); }
public static void SkillExecute(int skillID, Database.Player.RACE race, Database.Player pAttacker, int targetID = 0, Map.Nod position = null) { if (!pAttacker.isCastingSkill || pAttacker.currentCastingSkillID != skillID) { Output.WriteLine("SkillHandler::SkillExecute " + " Try to cast skill but isCastingSkill is FALSE or skill ID missmatch"); return; // if no Skillrequest executed or player break the skill execute then return } Skill skill = null; Dictionary <int, Skill> dict = null; ActiveSkill activeSkill; if (!pAttacker.activeSkillList.TryGetValue(skillID, out activeSkill)) { throw new KeyNotFoundException(); } try { switch (race) { case Database.Player.RACE.KNIGHT: dict = knightSkillList; break; case Database.Player.RACE.MAGE: dict = mageSkillList; break; case Database.Player.RACE.ARCHER: dict = archerSkillList; break; default: throw new NullReferenceException(); break; } skill = dict[skillID]; } catch (KeyNotFoundException e) { Output.WriteLine("SkillHandler::SkillExecute " + "Someone tried to execute a skill for that no handler exists. " + e.Source.ToString() + " : " + e.TargetSite.ToString()); } catch (NullReferenceException) { // Should never ever happen -.- Output.WriteLine("SkillHandler::SkillExecute " + "Someone tried to request a skill for an unknown race!"); } if (activeSkill.ElapsedCast() > 0 && activeSkill.ElapsedCast() < skill.castTime) { Output.WriteLine(ConsoleColor.Red, "SkillHandler::SkillExecute - can't cast skill (still in cast time)"); Output.WriteLine(ConsoleColor.Red, "SkillHandler::SkillExecute cast time: " + activeSkill.ElapsedCast().ToString()); return; } Output.WriteLine(ConsoleColor.DarkGreen, "SkillHandler::SkillExecute cast time: " + activeSkill.ElapsedCast().ToString()); //this is place where we do actions for execution the skill Output.WriteLine("SkillExecute: " + skill.name); Output.WriteLine("cast time: " + skill.castTime); Output.WriteLine("cool down: " + skill.coolDown); Output.WriteLine("info: " + skill.info); Output.WriteLine("lvl: " + skill.lvl); Output.WriteLine("mana cost: " + skill.manaCost); Output.WriteLine("race: " + skill.race); Output.WriteLine("range: " + skill.range); activeSkill.StartCoolDown(); activeSkill.startCast = DateTime.UtcNow; pAttacker.isCastingSkill = false; pAttacker.currentCastingSkillID = -1; //BroadcastPacket bPacket = new BroadcastPacket((uint)pAttacker.PosX, (uint)pAttacker.PosY, (int)World.DEBUG_SIGHT_RANGE, new Packet.SendPacketHandlers.AttackMag(pAttacker.PlayerPID, targetID, activeSkill.skillID, activeSkill.skillLvl)); //GameServer.world.broadcastQueue.Enqueue(bPacket); switch (skill.demageFlag) { //skills that need to give target entity case SKILL_DEMAGE_FLAG.SINGLE_TARGET_FLAG: case SKILL_DEMAGE_FLAG.MULTI_TARGET_FLAG: { Action act = new Action(activeSkill, skill, pAttacker, targetID); GameServer.world.actions.Enqueue(act); Output.WriteLine("Skill enqueue as target skill"); } break; //skills that are place related not target entity case SKILL_DEMAGE_FLAG.POSITION_TARGET_FLAG: case SKILL_DEMAGE_FLAG.CON_45_FLAG: case SKILL_DEMAGE_FLAG.CON_90_FLAG: case SKILL_DEMAGE_FLAG.AOE_TARGET_FLAG: { Action act = new Action(activeSkill, skill, pAttacker, position); GameServer.world.actions.Enqueue(act); Output.WriteLine("Skill enqueue as position skill"); } break; default: Output.WriteLine("Skill has inncorrect DEMAGE FLAG SET"); break; } }
public static void GameServerLogin(Connection pConn, byte[] data) { if (data.Length <= 5) { Output.WriteLine("RecvPacketHandlers::GameServerLogin Wrong packet size"); pConn.Close(); } int uid = data[Program.receivePrefixLength]; int pid = data[Program.receivePrefixLength + 4]; byte[] guid = new byte[16]; Array.Copy(data, Program.receivePrefixLength + 4 + 4, guid, 0, 16); Output.WriteLine("RecvPacketHandlers::GameServerLogin Recv UID: " + uid.ToString() + " PID: " + pid.ToString() + " GUID: " + GameServer.ByteArrayToHex(guid)); UsersLobby.LobbyUser uLob = null; UsersLobby.Remove(uid, out uLob); if (uLob != null) { //its ok to process check if (uid == uLob.UserID && pid == uLob.PlayerID && GameServer.ByteArrayCompare(guid, uLob.GUID)) { pConn.client.UserID = uid; pConn.client.PlayerID = pid; //client succesfull authenticated Database.Player player = Database.DB_Acces.GetPlayer(pid, pConn); if (player == null) { Output.WriteLine("RecvPacketHandlers::GameServerLogin Not existing player PID: " + pid.ToString()); pConn.Close(); return; } /* * if (!InGameUsers.Add(uid, pid, pConn)) * { * InGameUsers.GameUser gUser = null; * InGameUsers.Remove(uid, out gUser); * if (gUser != null) * { * gUser.UserConnection.Send(new SendPacketHandlers.LoginError(SendPacketHandlers.LOGIN_ERROR.CURRENTLY_LOGGED)); * gUser.UserConnection.Close(); * } * if (!InGameUsers.Add(uid, pid, pConn)) * { * //shouldn't happen * pConn.Close(); * return; * } * } */ //send info to te Login server about succesfull user login if (LoginServerInterface.LoginServerConnection != null) { LoginServerInterface.LoginServerConnection.SendSync(new Packet.LoginServerSend.UserInGame(pConn.client.UserID)); } pConn.client.SetPlayer(player); pConn.client.recvKeyCOD = uLob.StartKey; pConn.client.sendKeyCOD = uLob.StartKey; pConn.client.DecodeType = Client.DECODE_TYPE.COD; pConn.client.EncodeType = Client.ENCODE_TYPE.COD; Output.WriteLine("RecvPacketHandlers::GameServerLogin User succesfully authenticated"); pConn.SendAsync(new Packet.SendPacketHandlers.PlayerData()); pConn.SendAsync(new Packet.SendPacketHandlers.PlayerSkills()); pConn.SendAsync(new Packet.SendPacketHandlers.Inventory()); //pConn.Send(new Packet.SendPacketHandlers.PlayerSpawn(pConn)); //pConn.client.AddPlayer(player); if (!GameServer.world.AddPlayer(player)) { Output.WriteLine("RecvPacketHandlers::GameServerLogin User failed add to map"); return; } /* * List<Database.Player> pList = GameServer.world.PlayersInSightRange(player.PosX, player.PosY, World.DEBUG_SIGHT_RANGE); * List<Database.Mob> mList = GameServer.world.MobsInSightRange(player.PosX, player.PosY, World.DEBUG_SIGHT_RANGE); * foreach(Database.Player p in pList) * { * if (p.PlayerPID != pConn.client.PlayerID) * { * pConn.client.GetPlayer().AddPlayer(p.PlayerPID); * pConn.Send(new Packet.SendPacketHandlers.PlayerSpawn(p.Con));//send p in this point - data about other players to this player * } * } * foreach (Database.Mob m in mList) * { * pConn.client.GetPlayer().AddMob(m.InternalID); * pConn.Send(new Packet.SendPacketHandlers.MobSpawn(m));//send m in this point - data about other mobs to this player * } */ } else { Output.WriteLine("RecvPacketHandlers::GameServerLogin Client not authenticated by Login server &0x001"); Output.WriteLine("RecvPacketHandlers::GameServerLogin Client UID: " + uid.ToString() + " PID: " + pid.ToString() + " GUID: " + GameServer.ByteArrayToHex(guid)); Output.WriteLine("RecvPacketHandlers::GameServerLogin From S UID: " + uLob.UserID.ToString() + " PID: " + uLob.PlayerID.ToString() + " GUID: " + GameServer.ByteArrayToHex(uLob.GUID)); pConn.Close(); } } else { Output.WriteLine("RecvPacketHandlers::GameServerLogin Client not authenticated by Login server &0x002"); pConn.Close(); } }
//User select character to log in game public static void CharacterSelect(Connection pConn, byte[] data) { if (Program.DEBUG_recv_stage1 || Program.DEBUG_recv) { Output.WriteLine("RecvPacketHandlers::CharacterSelect Recv select char packet"); } if (pConn.client.Status != Client.STATUS.CharSelect) { if (Program.DEBUG_recv) { Output.WriteLine("RecvPacketHandlers::CharacterSelect - Error recv CharacterSelect beafore login, close connection"); } pConn.Close(); return; } int playerID = BitConverter.ToInt32(data, Program.receivePrefixLength); Database.Player p = pConn.client.GetPlayer(playerID); if (p == null) { if (Program.DEBUG_recv) { Output.WriteLine("RecvPacketHandlers::CharacterSelect Selected non existing player!"); } pConn.Close(); return; } else { //tell correct GameServer about new player login in //send to the User data about connection to GameServer //close connection with succesful transfered connection to GameServer and save it to the GameClient dictionary ( already connected and in game) WorldConnectionListener.GameServer gs = Worlds.GetServer(p.PosX, p.PosY); if (gs != null && gs.Connected) { if (Program.DEBUG_recv) { Output.WriteLine("RecvPacketHandlers::CharacterSelect Selected world: " + gs.Name + " size: [" + gs.StartX.ToString() + "," + gs.StartY.ToString() + "::" + gs.EndX.ToString() + "," + gs.EndY.ToString() + "]"); } if (InGameUsers.Exists(p.PlayerUID))// erro add this user to inGame list then close connection { pConn.Send(new SendPacketHandlers.LoginError(SendPacketHandlers.LOGIN_ERROR.NOT_ALLOWED)); if (Program.DEBUG_recv) { Output.WriteLine("RecvPacketHandlers::CharacterSelect User already exists in game!"); } } else// send to client info about GameServer and send info to Game server about client { if (Program.DEBUG_recv) { Output.WriteLine("RecvPacketHandlers::CharacterSelect Transfer connection to correct GameServer for selected player name: " + p.PlayerName); } byte[] guid = System.Guid.NewGuid().ToByteArray(); byte key = (byte)Program.rnd.Next(Program.maxGameServerStartKeyValue); gs.connection.Send(new Packet.GameServerSend.User_Login(pConn.client.UserID, playerID, guid, key)); pConn.Send(new Packet.SendPacketHandlers.GameServer(gs.UserIP, gs.UserPort, key, guid, gs.GridSize, gs.TileSizeX, gs.TileSizeY, gs.Xmultiplikator, gs.Ymultiplikator)); } } else { Output.WriteLine("RecvPacketHandlers::CharacterSelect Thers no Game Server for position [" + p.PosX.ToString() + "," + p.PosY.ToString() + "]"); pConn.Send(new Packet.SendPacketHandlers.GameServerBusy()); //pConn.Close(); } //finally close current connection pConn.Close(); } }
public override void HandlePacket(Client context, byte[] data, uint position, uint size) { PacketReader reader = new Packets.PacketReader(data, position, size); reader.BaseStream.Seek(0x2C, SeekOrigin.Current); uint macCount = reader.ReadMagic(0x5E6, 107); reader.BaseStream.Seek(0x1C * macCount, SeekOrigin.Current); reader.BaseStream.Seek(0x114, SeekOrigin.Current); string username = reader.ReadFixedLengthASCII(64); string password = reader.ReadFixedLengthASCII(64); // What am I doing here even var db = PolarisApp.Instance.Database; var users = from u in db.Players where u.Username == username select u; string error = ""; Database.Player user = null; if (users.Count() == 0) { // Check if there is an empty field if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password)) { error = "Username and password fields must not be empty."; user = null; } // Check for special characters else if (!System.Text.RegularExpressions.Regex.IsMatch(username, "^[a-zA-Z0-9 ]*$", System.Text.RegularExpressions.RegexOptions.IgnoreCase)) { error = "Username must not contain special characters.\nPlease use letters and numbers only."; user = null; } else // We're all good! { // Insert new player into database user = new Database.Player { Username = username, Password = BCrypt.Net.BCrypt.HashPassword(password), Nickname = username, // Since we can't display the nickname prompt yet, just default it to the username SettingsINI = System.IO.File.ReadAllText("Resources/settings.txt") }; db.Players.Add(user); db.SaveChanges(); // context.SendPacket(0x11, 0x1e, 0x0, new byte[0x44]); // Request nickname } } else { user = users.First(); if (!BCrypt.Net.BCrypt.Verify(password, user.Password)) { error = "Incorrect password."; user = null; } } // Mystery packet PacketWriter mystery = new PacketWriter(); mystery.Write((uint)100); // SendPacket(0x11, 0x49, 0, mystery.ToArray()); // Login response packet PacketWriter resp = new PacketWriter(); resp.Write((uint)((user == null) ? 1 : 0)); // Status flag: 0=success, 1=error resp.WriteUTF16(error, 0x8BA4, 0xB6); if (user == null) { for (int i = 0; i < 0xEC; i++) { resp.Write((byte)0); } context.SendPacket(0x11, 1, 4, resp.ToArray()); return; } resp.Write((uint)user.PlayerID); // Player ID resp.Write((uint)0); // Unknown resp.Write((uint)0); // Unknown resp.WriteFixedLengthUTF16("B001-DarkFox", 0x20); for (int i = 0; i < 0xBC; i++) { resp.Write((byte)0); } context.SendPacket(0x11, 1, 4, resp.ToArray()); // Settings packet PacketWriter settings = new PacketWriter(); settings.WriteASCII(user.SettingsINI, 0x54AF, 0x100); context.SendPacket(0x2B, 2, 4, settings.ToArray()); context.User = user; // context.SendPacket(new SystemMessagePacket("I looooooove my Raxxy <3", SystemMessagePacket.MessageType.AdminMessage)); }