/// <summary> /// Creates a new packet based on the typeID and the received content /// inside the buffer. The user has to create an own implementation /// of this interface. /// </summary> public PacketBase createPacket(NetworkClient client, ushort typeID, byte[] buffer, int offset, int size) { //Ready our packet base PacketBase packet = null; size--; //Was it a system packet? if (buffer[offset++] == 0) { //Yes, find the appropriate type return(createSystemPacket(typeID, buffer, offset, size)); } //So what was the typeid? switch (typeID) { case CS_Login.TypeID: packet = new CS_Login(typeID, buffer, offset, size); break; case CS_ArenaJoin.TypeID: packet = new CS_ArenaJoin(typeID, buffer, offset, size); break; case CS_PlayerJoin.TypeID: packet = new CS_PlayerJoin(typeID, buffer, offset, size); break; case CS_Ready.TypeID: packet = new CS_Ready(typeID, buffer, offset, size); break; case CS_PlayerPickup.TypeID: packet = new CS_PlayerPickup(typeID, buffer, offset, size); break; case CS_PlayerDrop.TypeID: packet = new CS_PlayerDrop(typeID, buffer, offset, size); break; case CS_Chat.TypeID: packet = new CS_Chat(typeID, buffer, offset, size); break; case CS_PlayerUseItem.TypeID: packet = new CS_PlayerUseItem(typeID, buffer, offset, size); break; case CS_Explosion.TypeID: packet = new CS_Explosion(typeID, buffer, offset, size); break; case CS_PlayerUpdate.TypeID: packet = new CS_PlayerUpdate(typeID, buffer, offset, size); break; case CS_Shop.TypeID: packet = new CS_Shop(typeID, buffer, offset, size); break; case CS_ShopSkill.TypeID: packet = new CS_ShopSkill(typeID, buffer, offset, size); break; case CS_PlayerSwitch.TypeID: packet = new CS_PlayerSwitch(typeID, buffer, offset, size); break; case CS_PlayerFlag.TypeID: packet = new CS_PlayerFlag(typeID, buffer, offset, size); break; case CS_RequestUpdate.TypeID: packet = new CS_RequestUpdate(typeID, buffer, offset, size); break; case CS_StartUpdate.TypeID: packet = new CS_StartUpdate(typeID, buffer, offset, size); break; case CS_VehicleDeath.TypeID: packet = new CS_VehicleDeath(typeID, buffer, offset, size); break; case CS_PlayerPortal.TypeID: packet = new CS_PlayerPortal(typeID, buffer, offset, size); break; case CS_AllowSpectator.TypeID: packet = new CS_AllowSpectator(typeID, buffer, offset, size); break; case CS_RequestSpectator.TypeID: packet = new CS_RequestSpectator(typeID, buffer, offset, size); break; case CS_ItemExpired.TypeID: packet = new CS_ItemExpired(typeID, buffer, offset, size); break; case CS_PlayerProduce.TypeID: packet = new CS_PlayerProduce(typeID, buffer, offset, size); break; case CS_SetBanner.TypeID: packet = new CS_SetBanner(typeID, buffer, offset, size); break; case CS_FileSend.TypeID: packet = new CS_FileSend(typeID, buffer, offset, size); break; case CS_Environment.TypeID: packet = new CS_Environment(typeID, buffer, offset, size); break; case CS_Frames.TypeID: packet = new CS_Frames(typeID, buffer, offset, size); break; case CS_ChartRequest.TypeID: packet = new CS_ChartRequest(typeID, buffer, offset, size); break; case CS_SecurityCheck.TypeID: packet = new CS_SecurityCheck(typeID, buffer, offset, size); break; case CS_BallPickup.TypeID: packet = new CS_BallPickup(typeID, buffer, offset, size); break; case CS_BallDrop.TypeID: packet = new CS_BallDrop(typeID, buffer, offset, size); break; case CS_GoalScored.TypeID: packet = new CS_GoalScored(typeID, buffer, offset, size); break; case CS_VehiclePickup.TypeID: packet = new CS_VehiclePickup(typeID, buffer, offset, size); break; case CS_SendBanner.TypeID: packet = new CS_SendBanner(typeID, buffer, offset, size); break; case CS_DamageEvent.TypeID: packet = new CS_DamageEvent(typeID, buffer, offset, size); break; case CS_PlayerZoneDisconnected.TypeID: packet = new CS_PlayerZoneDisconnected(typeID, buffer, offset, size); break; case CS_RegResponse.TypeID: packet = new CS_RegResponse(typeID, buffer, offset, size); break; case CS_Unknown.TypeID: packet = new CS_Unknown(typeID, buffer, offset, size); break; default: //An undefined packet. packet = new PacketDummy(typeID, buffer, offset, size); break; } return(packet); }
/// <summary> /// Provides an easy means of routing movement update messages between players /// </summary> static public void Update_RoutePlayer(Player update, CS_PlayerUpdate pkt, int updateTick, int oldPosX, int oldPosY) { //Prepare the appropriate packets SC_PlayerTeamUpdate tu = new SC_PlayerTeamUpdate(); tu.tickUpdate = updateTick; tu.player = update; tu.vehicle = update.ActiveVehicle; tu.itemID = pkt.itemID; tu.activeEquip = pkt.activeEquip; SC_PlayerUpdate up = new SC_PlayerUpdate(); up.tickUpdate = updateTick; up.player = update; up.vehicle = update.ActiveVehicle; up.itemID = pkt.itemID; up.activeEquip = pkt.activeEquip; //Get the routing audience bool itemUpdate = false; bool itemRouteFriendly = false; int weaponRouteRange = 0; if (pkt.itemID != 0) { itemUpdate = true; ItemInfo item = _server._assets.getItemByID(pkt.itemID); if (item != null) { itemRouteFriendly = item.routeFriendly; item.getRouteRange(out weaponRouteRange); } else { Log.write(TLog.Warning, "Update_RoutePlayer(): item is null"); } } List <Player> audience = getRouteList(update._arena, update._state, itemUpdate, weaponRouteRange, update._spectators, oldPosX, oldPosY); //Send our updates.. foreach (Player player in audience) { //Don't send duplicates if (player == update) { continue; } //Are we updating an item? if (itemUpdate) { //Route friendly? if (itemRouteFriendly) { //Route only to teammates. if (player._team == update._team) { player._client.send(tu); } continue; } } if (player.IsSpectator || player._team == update._team) { player._client.send(tu); } else { player._client.send(up); } } }