/// <summary> /// Read and process Tell message /// </summary> /// <param name="client"> /// Client sending /// </param> /// <param name="packet"> /// Packet data /// </param> public static void Read(Client client, byte[] packet) { PacketReader reader = new PacketReader(ref packet); reader.ReadUInt16(); reader.ReadUInt16(); uint playerId = reader.ReadUInt32(); string message = reader.ReadString(); client.Server.Debug(client, "{0} >> Tell: PlayerId: {1}", client.Character.characterName, playerId); reader.Finish(); if (client.Server.ConnectedClients.ContainsKey(playerId)) { Client tellClient = (Client)client.Server.ConnectedClients[playerId]; if (!tellClient.KnownClients.Contains(client.Character.characterId)) { byte[] pname = PlayerName.New(client, client.Character.characterId); tellClient.Send(pname); tellClient.KnownClients.Add(client.Character.characterId); } byte[] pgroup = MsgPrivateGroup.Create(client.Character.characterId, message, string.Empty); tellClient.Send(pgroup); } else { byte[] sysmsg = MsgSystem.Create("Player not online."); client.Send(sysmsg); } }
/// <summary> /// The read. /// </summary> /// <param name="client"> /// </param> /// <param name="packet"> /// </param> public static void Read(Client client, byte[] packet) { // TODO: Fix this mess. ushort data_length = BitConverter.ToUInt16(new[] { packet[3], packet[2] }, 0); byte[] sender_ID = BitConverter.GetBytes(client.Character.characterId); Array.Reverse(sender_ID); MemoryStream m_stream = new MemoryStream(); m_stream.Write(packet, 0, 9); m_stream.Write(sender_ID, 0, 4); m_stream.Write(packet, 9, packet.Length - 9); m_stream.Capacity = (int)m_stream.Length; byte[] message = m_stream.GetBuffer(); byte[] new_length = BitConverter.GetBytes(message.Length - 4); message[2] = new_length[1]; message[3] = new_length[0]; m_stream.Close(); m_stream.Dispose(); foreach (Client m_client in client.Server.Clients) { if (!m_client.KnownClients.Contains(client.Character.characterId)) { byte[] pname = PlayerName.New(client, client.Character.characterId); m_client.Send(pname); m_client.KnownClients.Add(client.Character.characterId); } m_client.Send(message); } PacketReader reader = new PacketReader(ref packet); reader.ReadUInt16(); reader.ReadUInt16(); reader.ReadUInt16(); reader.ReadUInt16(); reader.ReadByte(); string text = reader.ReadString(); string channelName = ChatChannels.GetChannel(packet).Name; ChatLogger.WriteString(channelName, text, client.Character.characterName); }
/// <summary> /// The read. /// </summary> /// <param name="client"> /// </param> /// <param name="packet"> /// </param> public static void Read(Client client, ref byte[] packet) { MemoryStream m_stream = new MemoryStream(packet); BinaryReader m_reader = new BinaryReader(m_stream); // now we should do password check and then send OK or Error // sending OK now m_stream.Position = 12; short userNameLength = IPAddress.NetworkToHostOrder(m_reader.ReadInt16()); string userName = Encoding.ASCII.GetString(m_reader.ReadBytes(userNameLength)); short loginKeyLength = IPAddress.NetworkToHostOrder(m_reader.ReadInt16()); string loginKey = Encoding.ASCII.GetString(m_reader.ReadBytes(loginKeyLength)); uint characterId = BitConverter.ToUInt32(new[] { packet[11], packet[10], packet[9], packet[8] }, 0); LoginEncryption loginEncryption = new LoginEncryption(); if (loginEncryption.IsValidLogin(loginKey, client.ServerSalt, userName) && loginEncryption.IsCharacterOnAccount(userName, characterId)) { byte[] loginok = LoginOk.Create(); client.Send(loginok); } else { byte[] loginerr = LoginError.Create(); client.Send(loginerr); client.Server.DisconnectClient(client); byte[] invalid = BitConverter.GetBytes(characterId); ZoneCom.Client.SendMessage(99, invalid); return; } // server welcome message string motd = ConfigReadWrite.Instance.CurrentConfig.Motd; // save characters ID in client - note, this is usually 0 if it is a chat client connecting client.Character = new Character(characterId, client); // add client to connected clients list if (!client.Server.ConnectedClients.ContainsKey(client.Character.characterId)) { client.Server.ConnectedClients.Add(client.Character.characterId, client); } // add yourself to that list client.KnownClients.Add(client.Character.characterId); // and give client its own name lookup byte[] pname = PlayerName.New(client, client.Character.characterId); client.Send(pname); // send server welcome message to client byte[] anonv = MsgAnonymousVicinity.Create( string.Empty, string.Format(motd, AssemblyInfoclass.Description + " " + AssemblyInfoclass.AssemblyVersion), string.Empty); client.Send(anonv); // tell client to join channel "Global" // hardcoded right now foreach (ChannelsEntry channel in ChatChannels.ChannelNames) { byte[] chanGlobal = ChannelJoin.Create( channel.Id, channel.Name, channel.ChannelMode, new byte[] { 0x00, 0x00 }); client.Send(chanGlobal); } // First Attempt at Guild Channel.... // This code is completly untested however if it works // we will have to add some what for you to join GuildChat on creation of guild // and when you join a guild... this just connects you to it if you already exist in a guild // at character login.. enjoy hope it works.. I cant seem to test it my computer wont let me install the sql tables atm.. if (client.Character.orgId == 0) { } else { ulong channelBuffer = (ulong)ChannelType.Organization << 32; channelBuffer |= (uint)client.Character.orgId; byte[] guildChannel = ChannelJoin.Create(channelBuffer, client.Character.orgName, 0x8044, new byte[] { 0x00, 0x00 }); client.Send(guildChannel); } // Do Not Delete this just yet! // byte[] chn_global = new Packets.ChannelJoin().Create // ( // new byte[] { 0x04, 0x00, 0x00, 0x23, 0x28 }, // "Global", // 0x8044, // new byte[] { 0x00, 0x00 } // ); // client.Send(chn_global); }