mirror of
https://github.com/islehorse/HISP.git
synced 2025-04-08 22:25:42 +12:00
Implement duplicate login checks,
and fix item spawning.
This commit is contained in:
parent
519355a231
commit
18201596c8
9 changed files with 225 additions and 9 deletions
|
@ -51,6 +51,7 @@
|
||||||
},
|
},
|
||||||
"disconnect":{
|
"disconnect":{
|
||||||
"banned":"Your account has been BANNED. You will no longer be able to login",
|
"banned":"Your account has been BANNED. You will no longer be able to login",
|
||||||
|
"dupe_login":"Duplicate Login. Disconnecting Previous.",
|
||||||
"client_timeout":{
|
"client_timeout":{
|
||||||
"warn_after":10,
|
"warn_after":10,
|
||||||
"kick_after":25,
|
"kick_after":25,
|
||||||
|
@ -34339,6 +34340,13 @@
|
||||||
"starting_y":138
|
"starting_y":138
|
||||||
},
|
},
|
||||||
"places":{
|
"places":{
|
||||||
|
"zones":[
|
||||||
|
{"start_x":862,"end_x":967,"start_y":37,"end_y":123,"name":"Zebra"},
|
||||||
|
{"start_x":24,"end_x":56,"start_y":15,"end_y":47,"name":"Rat"},
|
||||||
|
{"start_x":275,"end_x":340,"start_y":290,"end_y":354,"name":"Butterflies"},
|
||||||
|
{"start_x":375,"end_x":389,"start_y":243,"end_y":252,"name":"Lawn"},
|
||||||
|
{"start_x":431,"end_x":442,"start_y":135,"end_y":148,"name":"Flamingo"}
|
||||||
|
],
|
||||||
"towns":[
|
"towns":[
|
||||||
{"start_x":219,"end_x":221,"start_y":136,"end_y":138,"name":"Tropicton Village"},
|
{"start_x":219,"end_x":221,"start_y":136,"end_y":138,"name":"Tropicton Village"},
|
||||||
{"start_x":307,"end_x":310,"start_y":102,"end_y":104,"name":"Rainy Meadows"},
|
{"start_x":307,"end_x":310,"start_y":102,"end_y":104,"name":"Rainy Meadows"},
|
||||||
|
|
|
@ -143,16 +143,141 @@ namespace HISP.Game
|
||||||
|
|
||||||
int despawnTimer = GameServer.RandomNumberGenerator.Next(900, 1500);
|
int despawnTimer = GameServer.RandomNumberGenerator.Next(900, 1500);
|
||||||
|
|
||||||
if (item.SpawnParamaters.SpawnInArea != null)
|
if (item.SpawnParamaters.SpawnInZone != null)
|
||||||
{
|
{
|
||||||
|
World.Zone spawnArea = World.GetZoneByName(item.SpawnParamaters.SpawnInZone);
|
||||||
|
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
// Pick a random location inside the zone
|
||||||
|
int tryX = GameServer.RandomNumberGenerator.Next(spawnArea.StartX, spawnArea.EndX);
|
||||||
|
int tryY = GameServer.RandomNumberGenerator.Next(spawnArea.StartY, spawnArea.EndY);
|
||||||
|
|
||||||
|
|
||||||
|
if (World.InSpecialTile(tryX, tryY))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
|
||||||
|
if (Map.CheckPassable(tryX, tryY)) // Can the player walk here?
|
||||||
|
{
|
||||||
|
int TileID = Map.GetTileId(tryX, tryY, false);
|
||||||
|
string TileType = Map.TerrainTiles[TileID - 1].Type; // Is it the right type?
|
||||||
|
|
||||||
|
if (item.SpawnParamaters.SpawnOnTileType == TileType)
|
||||||
|
{
|
||||||
|
ItemInstance instance = new ItemInstance(item.Id);
|
||||||
|
DroppedItem droppedItem = new DroppedItem();
|
||||||
|
droppedItem.X = tryX;
|
||||||
|
droppedItem.Y = tryY;
|
||||||
|
droppedItem.DespawnTimer = despawnTimer;
|
||||||
|
droppedItem.instance = instance;
|
||||||
|
droppedItemsList.Add(droppedItem);
|
||||||
|
Database.AddDroppedItem(droppedItem);
|
||||||
|
Logger.DebugPrint("Created Item ID: " + instance.ItemId + " in ZONE: " + spawnArea.Name + " at: X: " + droppedItem.X + " Y: " + droppedItem.Y);
|
||||||
|
newItems++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (item.SpawnParamaters.SpawnOnSpecialTile != null)
|
else if (item.SpawnParamaters.SpawnOnSpecialTile != null)
|
||||||
{
|
{
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
// Pick a random special tile
|
||||||
|
World.SpecialTile[] possileTiles = World.GetSpecialTilesByName(item.SpawnParamaters.SpawnOnSpecialTile);
|
||||||
|
World.SpecialTile spawnOn = possileTiles[GameServer.RandomNumberGenerator.Next(0, possileTiles.Length)];
|
||||||
|
|
||||||
|
if (Map.CheckPassable(spawnOn.X, spawnOn.Y))
|
||||||
|
{
|
||||||
|
ItemInstance instance = new ItemInstance(item.Id);
|
||||||
|
DroppedItem droppedItem = new DroppedItem();
|
||||||
|
droppedItem.X = spawnOn.X;
|
||||||
|
droppedItem.Y = spawnOn.Y;
|
||||||
|
droppedItem.DespawnTimer = despawnTimer;
|
||||||
|
droppedItem.instance = instance;
|
||||||
|
droppedItemsList.Add(droppedItem);
|
||||||
|
Database.AddDroppedItem(droppedItem);
|
||||||
|
Logger.DebugPrint("Created Item ID: " + instance.ItemId + " at: X: " + droppedItem.X + " Y: " + droppedItem.Y);
|
||||||
|
newItems++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (item.SpawnParamaters.SpawnNearSpecialTile != null)
|
else if (item.SpawnParamaters.SpawnNearSpecialTile != null)
|
||||||
{
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
// Pick a random special tile
|
||||||
|
World.SpecialTile[] possileTiles = World.GetSpecialTilesByName(item.SpawnParamaters.SpawnNearSpecialTile);
|
||||||
|
World.SpecialTile spawnNearTile = possileTiles[GameServer.RandomNumberGenerator.Next(0, possileTiles.Length)];
|
||||||
|
|
||||||
|
// Pick a direction to try spawn in
|
||||||
|
|
||||||
|
int direction = GameServer.RandomNumberGenerator.Next(0, 4);
|
||||||
|
int tryX = 0;
|
||||||
|
int tryY = 0;
|
||||||
|
if (direction == 0)
|
||||||
|
{
|
||||||
|
tryX = spawnNearTile.X + 1;
|
||||||
|
tryY = spawnNearTile.Y;
|
||||||
|
}
|
||||||
|
else if(direction == 1)
|
||||||
|
{
|
||||||
|
tryX = spawnNearTile.X - 1;
|
||||||
|
tryY = spawnNearTile.Y;
|
||||||
|
}
|
||||||
|
else if(direction == 3)
|
||||||
|
{
|
||||||
|
tryX = spawnNearTile.X;
|
||||||
|
tryY = spawnNearTile.Y + 1;
|
||||||
|
}
|
||||||
|
else if (direction == 4)
|
||||||
|
{
|
||||||
|
tryX = spawnNearTile.X;
|
||||||
|
tryY = spawnNearTile.Y - 1;
|
||||||
|
}
|
||||||
|
if (World.InSpecialTile(tryX, tryY))
|
||||||
|
{
|
||||||
|
World.SpecialTile tile = World.GetSpecialTile(tryX, tryY);
|
||||||
|
if (tile.Code != null)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Map.CheckPassable(tryX, tryY))
|
||||||
|
{
|
||||||
|
|
||||||
|
ItemInstance instance = new ItemInstance(item.Id);
|
||||||
|
DroppedItem droppedItem = new DroppedItem();
|
||||||
|
droppedItem.X = tryX;
|
||||||
|
droppedItem.Y = tryY;
|
||||||
|
droppedItem.DespawnTimer = despawnTimer;
|
||||||
|
droppedItem.instance = instance;
|
||||||
|
droppedItemsList.Add(droppedItem);
|
||||||
|
Database.AddDroppedItem(droppedItem);
|
||||||
|
Logger.DebugPrint("Created Item ID: " + instance.ItemId + " at: X: " + droppedItem.X + " Y: " + droppedItem.Y);
|
||||||
|
newItems++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (item.SpawnParamaters.SpawnOnTileType != null)
|
else if (item.SpawnParamaters.SpawnOnTileType != null)
|
||||||
|
@ -169,7 +294,7 @@ namespace HISP.Game
|
||||||
int tryY = GameServer.RandomNumberGenerator.Next(isle.StartY, isle.EndY);
|
int tryY = GameServer.RandomNumberGenerator.Next(isle.StartY, isle.EndY);
|
||||||
|
|
||||||
|
|
||||||
if (World.InTown(tryX, tryY) || World.InSpecialTile(tryX, tryY))
|
if (World.InSpecialTile(tryX, tryY))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (Map.CheckPassable(tryX, tryY)) // Can the player walk here?
|
if (Map.CheckPassable(tryX, tryY)) // Can the player walk here?
|
||||||
|
|
|
@ -13,7 +13,7 @@ namespace HISP.Game
|
||||||
public struct SpawnRules
|
public struct SpawnRules
|
||||||
{
|
{
|
||||||
public int SpawnCap;
|
public int SpawnCap;
|
||||||
public string SpawnInArea;
|
public string SpawnInZone;
|
||||||
public string SpawnOnTileType;
|
public string SpawnOnTileType;
|
||||||
public string SpawnOnSpecialTile;
|
public string SpawnOnSpecialTile;
|
||||||
public string SpawnNearSpecialTile;
|
public string SpawnNearSpecialTile;
|
||||||
|
|
|
@ -79,8 +79,6 @@ namespace HISP.Game
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Logger.DebugPrint("Overlay: " + otileId + " Terrain: " + tileId);
|
|
||||||
|
|
||||||
return passable;
|
return passable;
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,6 +144,7 @@ namespace HISP.Game
|
||||||
|
|
||||||
// Disconnect Messages
|
// Disconnect Messages
|
||||||
public static string BanMessage;
|
public static string BanMessage;
|
||||||
|
public static string DuplicateLogin;
|
||||||
public static string IdleKickMessageFormat;
|
public static string IdleKickMessageFormat;
|
||||||
|
|
||||||
// Swf
|
// Swf
|
||||||
|
|
|
@ -32,6 +32,15 @@ namespace HISP.Game
|
||||||
public string Name;
|
public string Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public struct Zone
|
||||||
|
{
|
||||||
|
public int StartX;
|
||||||
|
public int EndX;
|
||||||
|
public int StartY;
|
||||||
|
public int EndY;
|
||||||
|
public string Name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public struct Time
|
public struct Time
|
||||||
{
|
{
|
||||||
|
@ -60,6 +69,8 @@ namespace HISP.Game
|
||||||
public static List<Isle> Isles = new List<Isle>();
|
public static List<Isle> Isles = new List<Isle>();
|
||||||
public static List<Town> Towns = new List<Town>();
|
public static List<Town> Towns = new List<Town>();
|
||||||
public static List<Area> Areas = new List<Area>();
|
public static List<Area> Areas = new List<Area>();
|
||||||
|
public static List<Zone> Zones = new List<Zone>();
|
||||||
|
|
||||||
public static List<SpecialTile> SpecialTiles = new List<SpecialTile>();
|
public static List<SpecialTile> SpecialTiles = new List<SpecialTile>();
|
||||||
public static void TickWorldClock()
|
public static void TickWorldClock()
|
||||||
{
|
{
|
||||||
|
@ -93,6 +104,18 @@ namespace HISP.Game
|
||||||
Logger.InfoPrint("It is " + ServerTime.Minutes / 60 + ":" + ServerTime.Minutes % 60 + " on Day " + ServerTime.Days + " in Year " + ServerTime.Years + "!!!");
|
Logger.InfoPrint("It is " + ServerTime.Minutes / 60 + ":" + ServerTime.Minutes % 60 + " on Day " + ServerTime.Days + " in Year " + ServerTime.Years + "!!!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool InZone(int x, int y)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
GetZone(x, y);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (KeyNotFoundException)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
public static bool InArea(int x, int y)
|
public static bool InArea(int x, int y)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -144,6 +167,27 @@ namespace HISP.Game
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public static Zone GetZoneByName(string name)
|
||||||
|
{
|
||||||
|
foreach(Zone zone in Zones)
|
||||||
|
{
|
||||||
|
if (zone.Name == name)
|
||||||
|
return zone;
|
||||||
|
}
|
||||||
|
throw new KeyNotFoundException("Zone not found.");
|
||||||
|
}
|
||||||
|
public static SpecialTile[] GetSpecialTilesByName(string name)
|
||||||
|
{
|
||||||
|
List<SpecialTile> tiles = new List<SpecialTile>();
|
||||||
|
foreach(SpecialTile tile in SpecialTiles)
|
||||||
|
{
|
||||||
|
if(tile.Title == name)
|
||||||
|
{
|
||||||
|
tiles.Add(tile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tiles.ToArray();
|
||||||
|
}
|
||||||
public static SpecialTile GetSpecialTile(int x, int y)
|
public static SpecialTile GetSpecialTile(int x, int y)
|
||||||
{
|
{
|
||||||
foreach(SpecialTile specialTile in SpecialTiles)
|
foreach(SpecialTile specialTile in SpecialTiles)
|
||||||
|
@ -168,6 +212,18 @@ namespace HISP.Game
|
||||||
throw new KeyNotFoundException("x,y not in an isle!");
|
throw new KeyNotFoundException("x,y not in an isle!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Zone GetZone(int x, int y)
|
||||||
|
{
|
||||||
|
foreach (Zone zone in Zones)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (zone.StartX <= x && zone.EndX >= x && zone.StartY <= y && zone.EndY >= y)
|
||||||
|
{
|
||||||
|
return zone;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new KeyNotFoundException("x,y not in an zone!");
|
||||||
|
}
|
||||||
public static Area GetArea(int x, int y)
|
public static Area GetArea(int x, int y)
|
||||||
{
|
{
|
||||||
foreach (Area area in Areas)
|
foreach (Area area in Areas)
|
||||||
|
|
|
@ -68,8 +68,8 @@ namespace HISP.Player
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
Database.SetPlayerMoney(value, Id);
|
|
||||||
money = value;
|
money = value;
|
||||||
|
Database.SetPlayerMoney(value, Id);
|
||||||
GameServer.UpdatePlayer(LoggedinClient);
|
GameServer.UpdatePlayer(LoggedinClient);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ namespace HISP.Server
|
||||||
|
|
||||||
private void warnTimerTick(object state)
|
private void warnTimerTick(object state)
|
||||||
{
|
{
|
||||||
|
warnTimer.Change(0, 0);
|
||||||
Logger.DebugPrint("Sending inactivity warning to: " + RemoteIp);
|
Logger.DebugPrint("Sending inactivity warning to: " + RemoteIp);
|
||||||
byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatIdleWarningMessage(), PacketBuilder.CHAT_BOTTOM_RIGHT);
|
byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatIdleWarningMessage(), PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||||
SendPacket(chatPacket);
|
SendPacket(chatPacket);
|
||||||
|
@ -57,6 +58,16 @@ namespace HISP.Server
|
||||||
}
|
}
|
||||||
public void Login(int id)
|
public void Login(int id)
|
||||||
{
|
{
|
||||||
|
// Check for duplicate
|
||||||
|
foreach(GameClient Client in GameServer.ConnectedClients)
|
||||||
|
{
|
||||||
|
if(Client.LoggedIn)
|
||||||
|
{
|
||||||
|
if (Client.LoggedinUser.Id == id)
|
||||||
|
Client.Kick(Messages.DuplicateLogin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
LoggedinUser = new User(this,id);
|
LoggedinUser = new User(this,id);
|
||||||
LoggedIn = true;
|
LoggedIn = true;
|
||||||
|
|
||||||
|
|
|
@ -32,10 +32,26 @@ namespace HISP.Server
|
||||||
|
|
||||||
Logger.DebugPrint("Registered Town: " + town.Name + " X " + town.StartX + "-" + town.EndX + " Y " + town.StartY + "-" + town.EndY);
|
Logger.DebugPrint("Registered Town: " + town.Name + " X " + town.StartX + "-" + town.EndX + " Y " + town.StartY + "-" + town.EndY);
|
||||||
World.Towns.Add(town);
|
World.Towns.Add(town);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Register Zones
|
||||||
|
int totalZones = gameData.places.zones.Count;
|
||||||
|
for (int i = 0; i < totalZones; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
World.Zone zone = new World.Zone();
|
||||||
|
zone.StartX = gameData.places.zones[i].start_x;
|
||||||
|
zone.StartY = gameData.places.zones[i].start_y;
|
||||||
|
zone.EndX = gameData.places.zones[i].end_x;
|
||||||
|
zone.EndY = gameData.places.zones[i].end_y;
|
||||||
|
zone.Name = gameData.places.zones[i].name;
|
||||||
|
|
||||||
|
Logger.DebugPrint("Registered Zone: " + zone.Name + " X " + zone.StartX + "-" + zone.EndX + " Y " + zone.StartY + "-" + zone.EndY);
|
||||||
|
World.Zones.Add(zone);
|
||||||
|
}
|
||||||
|
|
||||||
// Register Areas
|
// Register Areas
|
||||||
int totalAreas = gameData.places.towns.Count;
|
int totalAreas = gameData.places.areas.Count;
|
||||||
for (int i = 0; i < totalAreas; i++)
|
for (int i = 0; i < totalAreas; i++)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -184,7 +200,7 @@ namespace HISP.Server
|
||||||
item.Effects = effectsList;
|
item.Effects = effectsList;
|
||||||
item.SpawnParamaters = new Item.SpawnRules();
|
item.SpawnParamaters = new Item.SpawnRules();
|
||||||
item.SpawnParamaters.SpawnCap = gameData.item.item_list[i].spawn_parameters.spawn_cap;
|
item.SpawnParamaters.SpawnCap = gameData.item.item_list[i].spawn_parameters.spawn_cap;
|
||||||
item.SpawnParamaters.SpawnInArea = gameData.item.item_list[i].spawn_parameters.spawn_in_area;
|
item.SpawnParamaters.SpawnInZone = gameData.item.item_list[i].spawn_parameters.spawn_in_area;
|
||||||
item.SpawnParamaters.SpawnOnTileType = gameData.item.item_list[i].spawn_parameters.spawn_on_tile_type;
|
item.SpawnParamaters.SpawnOnTileType = gameData.item.item_list[i].spawn_parameters.spawn_on_tile_type;
|
||||||
item.SpawnParamaters.SpawnOnSpecialTile = gameData.item.item_list[i].spawn_parameters.spawn_on_special_tile;
|
item.SpawnParamaters.SpawnOnSpecialTile = gameData.item.item_list[i].spawn_parameters.spawn_on_special_tile;
|
||||||
item.SpawnParamaters.SpawnNearSpecialTile = gameData.item.item_list[i].spawn_parameters.spawn_near_special_tile;
|
item.SpawnParamaters.SpawnNearSpecialTile = gameData.item.item_list[i].spawn_parameters.spawn_near_special_tile;
|
||||||
|
@ -528,6 +544,7 @@ namespace HISP.Server
|
||||||
Messages.BanMessage = gameData.messages.disconnect.banned;
|
Messages.BanMessage = gameData.messages.disconnect.banned;
|
||||||
Messages.IdleKickMessageFormat = gameData.messages.disconnect.client_timeout.kick_message;
|
Messages.IdleKickMessageFormat = gameData.messages.disconnect.client_timeout.kick_message;
|
||||||
Messages.IdleWarningFormat = gameData.messages.disconnect.client_timeout.warn_message;
|
Messages.IdleWarningFormat = gameData.messages.disconnect.client_timeout.warn_message;
|
||||||
|
Messages.DuplicateLogin = gameData.messages.disconnect.dupe_login;
|
||||||
|
|
||||||
Chat.PrivateMessageSound = gameData.messages.chat.pm_sound;
|
Chat.PrivateMessageSound = gameData.messages.chat.pm_sound;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue