Ejemplo n.º 1
0
        /// <summary>Sends a communication message (tell, say, etc.) to the player.  Since we are sending this player the message, it is the listener.</summary>
        /// <param name="fromName">An optionally blank speaker's name.</param>
        /// <param name="toName">An optionally blank target's name.</param>
        /// <remarks>Messages should already be scrubbed for validity (GM messages intended only for GMs, etc.)</remarks>
        internal void SendChannelMessage(string fromName, string toName, MessageChannel chan, Language lang, int langSkill, string message)
        {
            ChannelMessage cm = new ChannelMessage();
            cm.ChannelId = (int)chan;
            cm.Message = message;
            cm.SpeakerName = string.IsNullOrEmpty(fromName) ? "ZServer" : fromName;     // Why 'ZServer'?

            // Looks like even though we know who the message is intended for, the target field can be blank
            if (!string.IsNullOrEmpty(toName))
                cm.TargetName = toName;
            else if (chan == MessageChannel.Tell)
                cm.TargetName = this.Name;

            int listenerSkill;
            if ((int)lang < Character.MAX_LANGUAGE) {   // Is the language being spoken within the allowable range
                listenerSkill = this.PlayerProfile.Languages[(int)lang];
                cm.LanguageId = (int)lang;
                if (chan == MessageChannel.Group && listenerSkill < 100) {  // group messages in unmastered languages, check for skill up
                    if ((this.PlayerProfile.Languages[(int)lang] <= langSkill) && fromName != this.Name)
                        CheckForSkillUp(lang, langSkill);
                }
            }
            else {
                // Not in allowable range, assume common tongue
                listenerSkill = this.PlayerProfile.Languages[(int)Language.CommonTongue];
                cm.LanguageId = (int)Language.CommonTongue;
            }

            // Set effective language skill = lower of sender and receiver skills
            int effSkill = Math.Min(langSkill, listenerSkill);
            effSkill = Math.Min(effSkill, 100); // Cap at 100
            cm.LanguageSkill = effSkill;

            EQRawApplicationPacket cmPack = new EQRawApplicationPacket(AppOpCode.ZonePlayerToBind, this.Client.IPEndPoint, cm.Serialize());
            this.Client.SendApplicationPacket(cmPack);
        }
Ejemplo n.º 2
0
        internal static ChannelMessage Deserialize(byte[] rawBytes)
        {
            ChannelMessage cm = new ChannelMessage();

            cm.TargetName = Encoding.ASCII.GetString(rawBytes, 0, 64);
            cm.SpeakerName = Encoding.ASCII.GetString(rawBytes, 64, 64);
            cm.LanguageId = BitConverter.ToInt32(rawBytes, 128);
            cm.ChannelId = BitConverter.ToInt32(rawBytes, 132);
            cm.LanguageSkill = BitConverter.ToInt32(rawBytes, 144);
            cm.Message = Encoding.ASCII.GetString(rawBytes, 148, rawBytes.Length - 148);  // easy since it's the last element in the byte array

            return cm;
        }