private void HandleAdminShowWindow(TcpSession session, Packet p) { //_logger.Debug("-C_ADMIN_SHOWINDOW_REQ-"); var ack = new Packet(EGamePacket.SAdminShowWindowAck); ack.Write((byte)0x00); // 0 = admin console active - >0 no console allowed session.Send(ack); }
private void HandleRemoveDeny(TcpSession session, Packet p) { var accID = p.ReadUInt64(); var nickname = p.ReadCStringBuffer(31); //_logger.Debug("-C_REMOVE_DENY_REQ- ID: {0} Nickname: {1}", accID, nickname); Player plr; if (!_players.TryGetValue(session.Guid, out plr)) { session.StopListening(); return; } var ack = new Packet(EChatPacket.SRemoveDenyAck); if (plr.DenyList.ContainsKey(accID)) { plr.DenyList.Remove(accID); GameDatabase.Instance.RemoveDeny(plr.AccountID, accID); ack.Write((byte)EDenyResult.OK); } else { ack.Write((byte)EDenyResult.Failed2); } ack.Write(accID); ack.WriteStringBuffer(nickname, 31); session.Send(ack); SendDenyList(plr); }
private static void HandleLoginRequest(TcpSession session, Packet p) { var serverList = AuthDatabase.Instance.GetServerList(); var ack = new Packet(EAuthPacket.SServerlistAck); ack.Write((byte)serverList.Count); foreach (var server in serverList) { ack.Write(server.ID); ack.Write(server.Type); ack.WriteStringBuffer(server.Name, 40); ack.Write(server.PlayersOnline); ack.Write(server.PlayerLimit); ack.Write(server.IP.GetAddressBytes()); ack.Write(server.Port); } session.Send(ack); }
private void HandleChannelListRequest(TcpSession session, Packet p) { //_logger.Debug("-C_CHANLIST_REQ-"); var ack = new Packet(EChatPacket.SChannelListAck); ack.Write((uint)_channels.Count); foreach (var chan in _channels.Values) { ack.Write((byte)chan.ID); // unk ack.Write((uint)chan.ID); // id?? ack.WriteStringBuffer(chan.Name, 21, Encoding.ASCII); } session.Send(ack); }
private void HandleGetData(TcpSession session, Packet p) { var accID = p.ReadUInt64(); //_logger.Debug("-C_GET_DATA_REQ- ID: {0}", accID); var ack = new Packet(EChatPacket.SGetDataAck); ack.Write(accID); // accid Player sender; if (!_players.TryGetValue(session.Guid, out sender)) { session.StopListening(); return; } var plr = _players.GetPlayerByID(accID); if(plr == null) { ack.Write((byte)0x01); session.Send(ack); return; } ack.Write((byte)0x00); // result code ack.WriteChatUserData(plr, true); session.Send(ack); }
private void HandleRepairItem(TcpSession session, Packet p) { var itemID = p.ReadUInt64(); Player player; if (!Players.TryGetValue(session.Guid, out player)) { session.StopListening(); return; } var itm = player.Inventory.FirstOrDefault(i => i.ID == itemID); if (itm == null) { session.StopListening(); return; } itm.Energy = itm.MaxEnergy; var ack = new Packet(EGamePacket.SRepairItemAck); ack.Write((byte)0); ack.Write(itemID); session.Send(ack); player.PEN -= 0; // repair cost player.UpdateMoney(); }
private void HandleAddFriend(TcpSession session, Packet p) { var accID = p.ReadUInt64(); var nickname = p.ReadCStringBuffer(31); //_logger.Debug("-C_ADD_FRIEND_REQ- ID: {0} Nickname: {1}", accID, nickname); Player plr; if (!_players.TryGetValue(session.Guid, out plr)) { session.StopListening(); return; } var ack = new Packet(EChatPacket.SAddFriendAck); ack.Write(accID); var plrToRequest = _players.GetPlayerByID(accID); if (plrToRequest == null) { ack.Write((byte)EAddFriendResult.DoenstExist); } else { var friend = plr.FriendList.FirstOrDefault(f => f.ID == accID); if (friend == null) { plr.FriendList.Add(new Friend() { ID = accID, Nickname = nickname, Accepted = false }); GameDatabase.Instance.AddFriend(plr.AccountID, accID, nickname); SendBRSFriendNotify(plr, plrToRequest, EFriendNotify.Request); ack.Write((byte)EAddFriendResult.MadeRequest); } else { if (friend.Accepted) ack.Write((byte)EAddFriendResult.AlreadyInList); else ack.Write((byte)EAddFriendResult.AlreadyRequested); } } ack.WriteStringBuffer(nickname, 31); session.Send(ack); }
private void HandleShuffle(TcpSession session, Packet p) { var ack = new Packet(EGamePacket.SResultAck); ack.Write((uint)EServerResult.FailedToRequestTask); session.Send(ack); }
private void SendRoomList(TcpSession session) { var ack = new Packet(EGamePacket.SRoomListAck); ack.Write((ushort)Rooms.Count); foreach (var room in Rooms.Values) { ack.Write(room.ID); ack.Write(room.GetConnectingCount()); //connecting people count ack.Write((byte)room.Players.Count); ack.Write((byte)room.State); ack.Write(room.GetPing()); // ping ack.Write(room.MatchKey); ack.WriteStringBuffer(room.Name, 31); ack.Write(room.PublicType); // has pw ack.Write(room.TimeLimit); ack.Write(room.ScoreLimit); ack.Write(room.IsFriendly); ack.Write(room.IsBalanced); ack.Write(room.MinLevel); ack.Write(room.MaxLevel); ack.Write(room.EquipLimit); ack.Write(room.IsNoIntrusion); } session.Send(ack); }
private void HandleChangeRoom(TcpSession session, Packet p) { //_logger.Debug("-C_CHANGE_ROOM_REQ-"); // TODO var ack = new Packet(EGamePacket.SResultAck); ack.Write((uint)EServerResult.FailedToRequestTask); session.Send(ack); }
private void HandleMovePlayer(TcpSession session, Packet p) { var targetID = p.ReadUInt64(); var unk = p.ReadUInt64(); var fromTeam = (ETeam) p.ReadByte(); var toTeam = (ETeam) p.ReadByte(); Player plr; if (!Players.TryGetValue(session.Guid, out plr)) { session.StopListening(); return; } if (plr.Room == null) return; if (plr.Room.State != EGameRuleState.Waiting) return; var targetPlr = plr.Room.Players.GetPlayerByID(targetID); if (targetPlr == null) return; var room = plr.Room; switch (toTeam) { case ETeam.Alpha: { var numAlpha = room.CountInTeam(ETeam.Alpha, targetPlr.GameMode); var limit = targetPlr.GameMode == EPlayerGameMode.Normal ? room.PlayerLimit / 2 : room.SpectatorLimit / 2; if (numAlpha >= limit) // full return; targetPlr.Team = ETeam.Alpha; } break; case ETeam.Beta: { var numBeta = room.CountInTeam(ETeam.Beta, targetPlr.GameMode); var limit = targetPlr.GameMode == EPlayerGameMode.Normal ? room.PlayerLimit / 2 : room.SpectatorLimit / 2; if (numBeta >= limit) // full return; targetPlr.Team = ETeam.Beta; } break; } var ack = new Packet(EGamePacket.SCRoomMovePlayer); ack.Write(targetID); ack.Write(unk); ack.Write((byte)fromTeam); ack.Write((byte)toTeam); session.Send(ack); room.BroadcastBriefing(); }
private void HandleLogout(TcpSession session, Packet p) { //_logger.Debug("-C_LOGOUT_REQ-"); Player plr; if (!Players.TryGetValue(session.Guid, out plr)) { session.StopListening(); return; } Players.TryRemove(session.Guid, out plr); var ack = new Packet(EGamePacket.SLogoutAck); session.Send(ack); }
private void HandleRandomShop(TcpSession session, Packet p) { var category = p.ReadByte(); // weapon = 1 - costume = 0 var typeID = p.ReadByte(); // weapon = 2 - costume = 1 //_logger.Debug("-C_RANDOMSHOP_REQ- Category: {0} TypeID: {1}", category, typeID); var ack = new Packet(EGamePacket.SResultAck); //ack.Write((uint)EServerResult.FailedToRequestTask); // session.Send(ack); // return; // TODO ack = new Packet(EGamePacket.SRandomshopItemInfoAck); ack.Write((byte)0); ack.Write(category); // category ack.Write((byte)80); // effect ack.Write((uint)1001); // item id ack.Write((uint)66125826); // skin id? ack.Write((uint)0); session.Send(ack); ack = new Packet(EGamePacket.SRandomshopChanceInfoAck); ack.Write((uint)10000); session.Send(ack); }
private void HandleAdminAction(TcpSession session, Packet p) { Logger.Debug("-C_ADMIN_ACTION_REQ-"); var cmd = p.ReadCString(); if (!cmd.StartsWith("/")) return; Player player; if (!Players.TryGetValue(session.Guid, out player)) { session.StopListening(); return; } cmd = cmd.Remove(0, 1); // remove / var args = HelperUtils.ParseArgs(cmd); foreach (var plugin in _pluginManager.Plugins) { var ret = plugin.OnAdminAction(player, args); if(string.IsNullOrEmpty(ret)) continue; var ack = new Packet(EGamePacket.SAdminActionAck); ack.Write((byte)0x01); // does not matter ack.Write((ushort)ret.Length); ack.Write(ret); session.Send(ack); } }
private void HandleBuyItem(TcpSession session, Packet p) { int count = p.ReadByte(); Player player; if (!Players.TryGetValue(session.Guid, out player)) { session.StopListening(); return; } var buyTime = DateTime.Now; var itemsToBuy = new List<Tuple<Item, ShopItem>>(); uint penCost = 0; uint apCost = 0; for (var i = 0; i < count; i++) { var item = new Item(); var mixedID = p.ReadBytes(4); item.Category = mixedID[0]; item.SubCategory = mixedID[1]; item.ItemID = BitConverter.ToUInt16(mixedID, 2); item.ProductID = p.ReadByte(); item.EffectID = p.ReadUInt32(); item.PurchaseTime = HelperUtils.GetUnixTimestamp(buyTime); var shopItem = GameDatabase.Instance.GetShopItem(item.Category, item.SubCategory, item.ItemID, item.ProductID); if (shopItem == null) // hacker { Logger.Error("-CBuyItemReq FAILED(HAX)- ItemID: {0} Category: {1} SubCategory: {2} Type: {3} EffectID: {4}", item.ItemID, item.Category, item.SubCategory, item.ProductID, item.EffectID); session.StopListening(); return; } item.Energy = shopItem.Energy; item.ExpireTime = (shopItem.Time == -1) ? -1 : HelperUtils.GetUnixTimestamp(buyTime.AddSeconds(shopItem.Time)); penCost += shopItem.Price; apCost += shopItem.Cash; itemsToBuy.Add(new Tuple<Item, ShopItem>(item, shopItem)); } Packet ack; if (player.PEN < penCost || player.AP < apCost) { ack = new Packet(EGamePacket.SBuyItemAck); ack.Write((byte)EBuyItemResult.NotEnoughMoney); session.Send(ack); return; } _pluginManager.OnBuyItem(player, itemsToBuy.Select(e => e.Item1).ToList()); foreach (var tuple in itemsToBuy) { var item = tuple.Item1; var shopItem = tuple.Item2; //_logger.Debug("-C_BUY_ITEM_REQ- ItemID: {0} Category: {1} SubCategory: {2} Type: {3} EffectID: {4}", item.ItemID, item.Category, item.SubCategory, item.ProductID, item.EffectID); player.PEN -= shopItem.Price; player.AP -= shopItem.Cash; var id = GameDatabase.Instance.CreateItem(item, player.AccountID); if (id == 0) { ack = new Packet(EGamePacket.SBuyItemAck); ack.Write((byte)EBuyItemResult.DBError); session.Send(ack); continue; } item.ID = id; item.SetupAPWeapon(); player.AddItem(item); ack = new Packet(EGamePacket.SBuyItemAck); ack.Write((byte)EBuyItemResult.OK); ack.Write(item.Category); ack.Write(item.SubCategory); ack.Write(item.ItemID); ack.Write(item.ProductID); ack.Write(item.EffectID); ack.Write(item.ID); session.Send(ack); } player.UpdateMoney(); }
private void HandleLoginRequest(TcpSession session, Packet p) { var ip = session.Client.Client.RemoteEndPoint as IPEndPoint; var username = p.ReadCStringBuffer(43); var sessionID = p.ReadUInt32(); var accID = AuthDatabase.Instance.GetAccountID(username); Logger.Info("-CLoginReq- User: {0} ID: {1} SessionID: {2}", username, accID, sessionID); Packet ack; if (accID == 0 || !ValidateSession(sessionID, accID, ip.Address)) { ack = new Packet(EGamePacket.SLoginAck); ack.Write((ulong)0); ack.Write((uint)5); session.Send(ack); session.StopListening(); return; } var player = GameDatabase.Instance.GetPlayer(accID); if (player == null) // new player! { player = new Player { Username = username, Nickname = AuthDatabase.Instance.GetNickname(accID), GMLevel = AuthDatabase.Instance.GetGMLevel(accID), AccountID = accID, PEN = GameConfig.Instance.StartPEN, AP = GameConfig.Instance.StartAP, DMStats = new DMStatistics(), TDStats = new TDStatistics() }; GameDatabase.Instance.CreatePlayer(player); } player.Session = session; player.SessionID = sessionID; GameDatabase.Instance.UpdateOnlineFlag(player.AccountID, true); if (Players.GetPlayerByID(player.AccountID) != null /* prevent multiple logins! */) { session.StopListening(); return; } Players.TryAdd(session.Guid, player); ack = new Packet(EGamePacket.SLoginAck); ack.Write(player.AccountID); ack.Write((uint)0); // error code session.Send(ack); #region License info ack = new Packet(EGamePacket.SLicenseInfoAck); ack.Write((byte)100); for (var i = 1; i <= 100; i++) ack.Write((byte)i); //foreach (var license in player.Licenses) //ack.Write((byte)license); session.Send(ack); #endregion #region Character info ack = new Packet(EGamePacket.SCharSlotInfoAck); ack.Write((byte)player.Characters.Count); // num chars ack.Write((byte)3); // num charslots ack.Write(player.ActiveCharSlot); // active char slot session.Send(ack); for (var i = 0; i < player.Characters.Count; i++) { var character = player.Characters[i]; ack = new Packet(EGamePacket.SOpenCharInfoAck); ack.Write(character.Slot); ack.Write((byte)0x01); ack.Write((byte)0x03); ack.Write((character.Avatar)); session.Send(ack); ack = new Packet(EGamePacket.SCharEquipInfoAck); ack.Write(character.Slot); ack.Write((byte)1); // skill counter ack.Write((byte)3); for (var j = 0; j < 3; j++) { for (var n = 0; n < 3; n++) { ack.Write((byte)n); ack.Write(character.Weapons[n]); } ack.Write((byte)0); ack.Write(character.Skill); } for (var j = 0; j < 7; j++) { ack.Write((byte)j); ack.Write(character.Clothes[j]); } session.Send(ack); } #endregion #region Inventory ack = new Packet(EGamePacket.SInventoryAck); ack.Write((uint)player.Inventory.Count); foreach (var item in player.Inventory) { ack.Write(item.ID); ack.Write(item.Category); ack.Write(item.SubCategory); ack.Write(item.ItemID); ack.Write(item.ProductID); ack.Write(item.EffectID); ack.Write(item.SellPrice); ack.Write(item.PurchaseTime); ack.Write(item.ExpireTime); ack.Write(item.Energy); ack.Write(item.TimeLeft); } session.Send(ack); #endregion ack = new Packet(EGamePacket.SResultAck); ack.Write((uint)0x27); session.Send(ack); #region Account info ack = new Packet(EGamePacket.SBeginAccountInfoAck); ack.Write((byte)0x00); ack.Write((byte)player.Level); ack.Write((uint)(player.CalculateTotalEXP() + player.EXP)); ack.Write((uint)0); // points?? ack.Write((uint)(player.TutorialCompleted ? 3 : 0)); ack.WriteStringBuffer(player.Nickname, 31); ack.Write((uint)0); // unk // dm stuff ack.Write(player.DMStats.Won); // wins? ack.Write(player.DMStats.Lost); // loses?? ack.Write((uint)player.DMStats.CalculateWinRate() >> 1); ack.Write((uint)0); ack.Write((uint)0); ack.Write((uint)0); ack.Write((uint)0); ack.Write((uint)0); ack.Write((uint)0); // td score stuff ack.Write(player.TDStats.CalculateWinRate()); // wins?? ack.Write(0); // loses? ack.Write(player.TDStats.TotalTouchdowns); ack.Write(20 * player.TDStats.TotalMatches); ack.Write(player.TDStats.TotalTouchdownAssists); ack.Write(player.TDStats.TotalKills); ack.Write(player.TDStats.TotalKillAssists); ack.Write(player.TDStats.TotalOffense); ack.Write(player.TDStats.TotalOffenseAssists); ack.Write(player.TDStats.TotalDefense); ack.Write(player.TDStats.TotalDefenseAssists); ack.Write(player.TDStats.TotalRecovery); ack.Write((uint)0); // Total / x / 2 ??? ack.Write((uint)0); // unk, nothing happens ack.Write((uint)0); // super increase for total score?? ack.Write((uint)0); // total score goes to 0?? ack.Write((uint)0); // unk, nothing happens ack.Write((uint)0); // unk, nothing happens session.Send(ack); #endregion ack = new Packet(EGamePacket.SResultAck); ack.Write((uint)0x11); session.Send(ack); }
private void HandleRefundItem(TcpSession session, Packet p) { var itemID = p.ReadUInt64(); Player player; if (!Players.TryGetValue(session.Guid, out player)) { session.StopListening(); return; } var itm = player.Inventory.FirstOrDefault(i => i.ID == itemID); if (itm == null) { session.StopListening(); return; } player.Inventory.Remove(itm); GameDatabase.Instance.RemoveItem(itemID); var ack = new Packet(EGamePacket.SRefundItemAck); ack.Write((byte)0); ack.Write(itemID); session.Send(ack); player.PEN += itm.SellPrice; player.UpdateMoney(); }
private void HandleCreateCharacter(TcpSession session, Packet p) { var slot = p.ReadByte(); var avatar = p.ReadUInt32(); //_logger.Debug("-C_CREATE_CHARACTER_REQ- Slot: {0} Avatar: {1}", slot, avatar); Player plr; if (!Players.TryGetValue(session.Guid, out plr)) { session.StopListening(); return; } if (plr.Characters.Count >= 3) // no cheating my friend! { session.StopListening(); return; } var character = new Character {Slot = slot, Avatar = avatar}; plr.Characters.Add(character); GameDatabase.Instance.CreateCharacter(plr.AccountID, slot, avatar); var ack = new Packet(EGamePacket.SCreateCharacterAck); ack.Write(slot); ack.Write(avatar); ack.Write((byte)1); // SKILL COUNT ack.Write((byte)3); // WEAPON COUNT session.Send(ack); }
private void HandleRefreshEQItems(TcpSession session, Packet p) { Player plr; if (!Players.TryGetValue(session.Guid, out plr)) { session.StopListening(); return; } var items = plr.Inventory; var res = items.Where(item => item.TimeLeft == 0); var ls = res as IList<Item> ?? res.ToList(); //_logger.Debug("-C_REFRESH_EQ_ITEMS_REQ- Count: {0}", ls.Count); var ack = new Packet(EGamePacket.SRefreshInvalidateEQItemsAck); ack.Write((byte)ls.Count()); foreach (var item in ls) { ack.Write(item.ID); } session.Send(ack); }
private void HandleDeleteCharacter(TcpSession session, Packet p) { var slot = p.ReadByte(); //_logger.Debug("-C_SELECT_CHARACTER_REQ- Slot: {0}", slot); Player plr; if (!Players.TryGetValue(session.Guid, out plr)) { session.StopListening(); return; } var res = plr.Characters.Where(c => c.Slot == slot); if (!res.Any()) // cheater { session.StopListening(); return; } var character = plr.Characters.First(c => c.Slot == slot); if (character == null) { session.StopListening(); return; } plr.Characters.Remove(character); GameDatabase.Instance.DeleteCharacter(plr.AccountID, slot); var ack = new Packet(EGamePacket.SDeleteCharacterAck); ack.Write(slot); session.Send(ack); }
private void HandleChannelEnter(TcpSession session, Packet p) { var chanName = p.ReadCString(); //_logger.Debug("-C_CHANENTER_REQ- Name: {0}", chanName); Player plr; if (!_players.TryGetValue(session.Guid, out plr)) { session.StopListening(); return; } var chan = _channels.GetChannelByName(chanName); if (chan.ID == 0) return; var ack = new Packet(EChatPacket.SChannelEnterAck); ack.Write((uint)chan.ID); session.Send(ack); }
private void HandleTimeSync(TcpSession session, Packet p) { var time = p.ReadUInt32(); var ts = DateTime.Now - Process.GetCurrentProcess().StartTime; var ack = new Packet(EGamePacket.STimeSyncAck); ack.Write(time); ack.Write((uint)ts.TotalMilliseconds); session.Send(ack); Player plr; if (!Players.TryGetValue(session.Guid, out plr)) return; plr.Ping = time - plr.LastSyncTime - 3000; plr.LastSyncTime = time; }
private void HandleCombiListRequest(TcpSession session, Packet p) { //_logger.Debug("-C_COMBILIST_REQ-"); Player plr; if (!_players.TryGetValue(session.Guid, out plr)) return; var ack = new Packet(EChatPacket.SCombiListAck); ack.Write(plr.AccountID); ack.Write((uint)0); session.Send(ack); }
async private void HandleChannelEnter(TcpSession session, Packet p) { var id = p.ReadUInt32(); //_logger.Debug("-C_CHAN_ENTER_REQ- ID: {0}", id); Player plr; if (!Players.TryGetValue(session.Guid, out plr)) { session.StopListening(); return; } Channel channel; if (!Channels.TryGetValue((ushort)id, out channel)) return; channel.Join(plr); var ack = new Packet(EGamePacket.SResultAck); ack.Write((uint)5); session.Send(ack); ack = new Packet(EGamePacket.SCashUpdateAck); ack.Write(plr.PEN); ack.Write(plr.AP); session.Send(ack); //if (plr.ConnectionType == 0x06) // Alice.SendMessageTo(plr.AccountID, "Mit deinem Router ist es leider nicht möglich hier zu spielen :("); //else if (plr.ConnectionType == 0x04) // Alice.SendMessageTo(plr.AccountID, "Mit deinem Router kannst du leider nur einen Raum erstellen :("); await Task.Delay(1000); SendRoomList(session); }
private void HandleLoginRequest(TcpSession session, Packet p) { var ip = session.Client.Client.RemoteEndPoint as IPEndPoint; var accID = p.ReadUInt64(); var nickname = p.ReadCString(); _logger.Info("-CLoginReq- User: {0} ID: {1}", nickname, accID); var ack = new Packet(EChatPacket.SLoginAck); if (accID == 0 || !ValidateSession(accID, nickname, ip.Address) || _players.GetPlayerByID(accID) != null /* prevent multiple logins! */) { ack.Write((uint)1); // error code session.Send(ack); session.StopListening(); return; } var plr = GameDatabase.Instance.GetPlayer(accID); plr.Session = session; _players.TryAdd(session.Guid, plr); ack.Write((uint)0); // error code session.Send(ack); }
private void HandleChannelLeave(TcpSession session, Packet p) { //_logger.Debug("-C_CHAN_LEAVE_REQ-"); Player plr; if (!Players.TryGetValue(session.Guid, out plr)) { session.StopListening(); return; } if (plr.Channel == null) return; plr.Channel.Leave(plr); var ack = new Packet(EGamePacket.SResultAck); ack.Write((uint)8); session.Send(ack); }
private void HandleSetDataRequest(TcpSession session, Packet p) { //_logger.Debug("-C_SETDATA_REQ-"); Player plr; if (!_players.TryGetValue(session.Guid, out plr)) { session.StopListening(); return; } p.ReadUInt16(); // unk p.ReadUInt64(); // accID plr.ServerID = p.ReadUInt16(); var channelID = p.ReadInt16(); var roomID = p.ReadInt32(); if(roomID == -1) roomID = 0; if (channelID == -1) channelID = 0; plr.Room = new Room(null, EServerType.Chat) { ID = (uint)roomID }; plr.CommunityByte = p.ReadByte(); p.ReadUInt32(); // total exp p.ReadBytes(32); // td/dm info plr.AllowCombiRequest = (EAllowCommunityRequest)p.ReadByte(); plr.AllowFriendRequest = (EAllowCommunityRequest)p.ReadByte(); plr.AllowInvite = (EAllowCommunityRequest)p.ReadByte(); plr.AllowInfoRequest = (EAllowCommunityRequest)p.ReadByte(); plr.CommunityData = p.ReadBytes(41); Channel channel; if (!_channels.TryGetValue((ushort)channelID, out channel)) return; if (plr.Channel == null && channelID > 0) // join { var ack = new Packet(EChatPacket.SChannelPlayerListInfoAck); ack.Write((uint)channel.ID); ack.Write(channel.Players.Count); foreach (var player in channel.Players.Values) ack.WriteChatUserData(player); session.Send(ack); channel.Join(plr); } else if(channelID == 0) // leave { if(plr.Channel != null) plr.Channel.Leave(plr); } else // update { var ack = new Packet(EChatPacket.SChannelPlayerListInfoAck); ack.Write((uint)channel.ID); ack.Write(channel.Players.Count); foreach (var player in channel.Players.Values) ack.WriteChatUserData(player); channel.Broadcast(ack); } }
private void HandleChannelInformation(TcpSession session, Packet p) { var t = p.ReadByte(); //_logger.Debug("-C_CHAN_INFO_REQ- Type: {0}", t); switch (t) { case 5: // channel info var ack = new Packet(EGamePacket.SChannelInfoAck); ack.Write((ushort)Channels.Count); foreach (var channel in Channels.Values) { ack.Write(channel.ID); ack.Write((ushort)channel.Players.Count); } session.Send(ack); break; case 4: // room info SendRoomList(session); break; case 3: // ?? break; } }
private void HandshakeConnection(string Type, IPEndPoint ip, string username, string password, TcpSession session, Packet ack) { switch (Type) { // Success case "success": var newSession = _sessions.AddSession(AuthDatabase.Instance.GetAccountID(username), ip.Address); _logger.Info("Succesfully authenticated Username: {0} with SessionID: {1}", username, newSession.SessionID); ack.Write(newSession.SessionID); // session id ack.Write(new byte[12]); // unk ack.Write((byte)ELoginResult.OK); session.Send(ack); break; // Invalid password/username combination case "failed": _logger.Error("Failed login for Username: {0}", username); ack.Write((uint)0); ack.Write(new byte[12]); ack.Write((byte)ELoginResult.AccountError); session.Send(ack); session.StopListening(); break; // Banned account tried to login case "banned": _logger.Error("Failed login for Username: {0}", username); ack.Write((uint)0); ack.Write(new byte[12]); ack.Write((byte)ELoginResult.AccountBlocked); session.Send(ack); session.StopListening(); break; default: break; } }
private void HandleBeginRound(TcpSession session, Packet p) { //_logger.Debug("-C_BEGINROUND_REQ-"); Player player; if (!Players.TryGetValue(session.Guid, out player)) { session.StopListening(); return; } var room = player.Room; if (room == null) return; if (room.MasterID != player.AccountID || room.State != EGameRuleState.Waiting) // cheater... return; if (_pluginManager.OnBeginRound(player, room)) return; if ((room.CountInTeamReady(ETeam.Alpha) == 0 || room.CountInTeamReady(ETeam.Beta) == 0) && room.GameRule != EGameRule.Survival) { var ack = new Packet(EGamePacket.SEventMessageAck); ack.WriteEventMessage(player.AccountID, EPlayerEventMessage.CantStartGame); session.Send(ack); return; } room.BeginRound(); }