Exemplo n.º 1
0
        public static void Broadcast(int hue, bool ascii, string text)
        {
            Packet p;

            if (ascii)
            {
                p = new AsciiMessage(Serial.MinusOne, -1, MessageType.Regular, hue, 3, "System", text);
            }
            else
            {
                p = new UnicodeMessage(Serial.MinusOne, -1, MessageType.Regular, hue, 3, "ENU", "System", text);
            }

            List <NetState> list = NetState.Instances;

            p.Acquire();

            for (int i = 0; i < list.Count; ++i)
            {
                if (list[i].Mobile != null)
                {
                    list[i].Send(p);
                }
            }

            p.Release();

            NetState.FlushAll();
        }
Exemplo n.º 2
0
        public static void Broadcast(int hue, bool ascii, string text)
        {
            Packet p;

            if (ascii)
            {
                p = new AsciiMessage(Serial.MinusOne, -1, MessageType.Regular, hue, 3, "System", text);
            }
            else
            {
                p = new UnicodeMessage(Serial.MinusOne, -1, MessageType.Regular, hue, 3, "ENU", "System", text);
            }

            p.Acquire();

            foreach (var client in GameServer.Instance.Clients)
            {
                if (client.Mobile != null)
                {
                    client.Send(p);
                    client.Flush();
                }
            }

            p.Release();
        }
Exemplo n.º 3
0
        public void PublicLOSMessage(MessageType type, int hue, bool ascii, string text)
        {
            Packet  p        = null;
            Point3D worldLoc = GetWorldLocation();

            IPooledEnumerable eable = GetClientsInRange(GetMaxUpdateRange());

            foreach (NetState state in eable)
            {
                Mobile m = state.Mobile;

                if (m.CanSee(this) && m.InRange(worldLoc, GetUpdateRange(m)) && this.Map.LineOfSight(this.Map.GetPoint(m, true), worldLoc))
                {
                    if (p == null)
                    {
                        if (ascii)
                        {
                            p = new AsciiMessage(Serial, ItemID, type, hue, 3, Name, text);
                        }
                        else
                        {
                            p = new UnicodeMessage(Serial, ItemID, type, hue, 3, "ENU", Name, text);
                        }
                        p.SetStatic();
                    }
                    state.Send(p);
                }
                Packet.Release(ref p);
            }
            eable.Free();
        }
Exemplo n.º 4
0
        public static void NonlocalOverheadMessage(this Item item, MessageType type, int hue, bool ascii, string text)
        {
            if (item == null || item.Map == null)
            {
                return;
            }

            Packet p;

            if (ascii)
            {
                p = new AsciiMessage(item.Serial, item.ItemID, type, hue, 3, item.Name, text);
            }
            else
            {
                p = new UnicodeMessage(item.Serial, item.ItemID, type, hue, 3, "ENU", item.Name, text);
            }

            p.Acquire();

            var eable = item.Map.GetClientsInRange(item.Location, item.GetMaxUpdateRange());

            foreach (var state in eable.Where(state => state.Mobile.CanSee(item)))
            {
                state.Send(p);
            }

            eable.Free();

            Packet.Release(p);
        }
Exemplo n.º 5
0
        public static void Broadcast(int hue, bool ascii, string text)
        {
            Packet p;

            if (ascii)
            {
                p = new AsciiMessage(Serial.MinusOne, -1, MessageType.Regular, hue, 3, "System", text);
            }
            else
            {
                p = new UnicodeMessage(Serial.MinusOne, -1, MessageType.Regular, hue, 3, "ENU", "System", text);
            }

            ArrayList list = NetState.Instances;

            for (int i = 0; i < list.Count; ++i)
            {
                if (((NetState)list[i]).Mobile != null)
                {
                    ((NetState)list[i]).Send(p);
                }
            }

            NetState.FlushAll();
        }
Exemplo n.º 6
0
        private static void SendChatMessage(CommandEventArgs e)
        {
            var msg = "[" + e.Mobile.Name + "]: " + e.ArgString;
            var hue = Hue;

            if (e.Mobile.AccessLevel > AccessLevel.Player)
            {
                hue = GMHue;
            }
            if (!(e.Mobile as MythikPlayerMobile).ChatEnabled)
            {
                e.Mobile.SendAsciiMessage("Enable Chat with .chaton");
                return;
            }
            Packet          p    = new AsciiMessage(Serial.MinusOne, -1, MessageType.Regular, hue, 3, "System", msg);
            List <NetState> list = NetState.Instances;

            p.Acquire();

            for (int i = 0; i < list.Count; ++i)
            {
                if (list[i].Mobile != null && ((MythikPlayerMobile)list[i].Mobile).ChatEnabled)
                {
                    list[i].Send(p);
                }
            }
            p.Release();
            NetState.FlushAll();
            ChatMessageSent?.Invoke(msg, new EventArgs());
        }
Exemplo n.º 7
0
        public virtual void WorldBroadcast(string message, params object[] args)
        {
            var text = String.Format(message, args);

            switch (Options.Broadcasts.World.Mode)
            {
            case PvPBattleWorldBroadcastMode.Notify:
            {
                foreach (var pm in GetWorldBroadcastList())
                {
                    pm.SendNotification(text, true, 0.5, 10.0);
                }
            }
            break;

            case PvPBattleWorldBroadcastMode.Broadcast:
            {
                Packet p = new AsciiMessage(
                    Server.Serial.MinusOne,
                    -1,
                    MessageType.Regular,
                    Options.Broadcasts.World.MessageHue,
                    3,
                    "System",
                    text);

                p.Acquire();

                foreach (var pm in GetWorldBroadcastList())
                {
                    pm.Send(p);
                }

                p.Release();
                NetState.FlushAll();
            }
            break;

            case PvPBattleWorldBroadcastMode.TownCrier:
            {
                foreach (var tc in TownCrier.Instances)
                {
                    tc.PublicOverheadMessage(
                        MessageType.Yell,
                        Options.Broadcasts.World.MessageHue,
                        true,
                        String.Format(message, args));
                }
            }
            break;

            default:
                return;
            }

            AutoPvP.InvokeBattleWorldBroadcast(this, text);
        }
Exemplo n.º 8
0
        /* I cant find any better way to send "speech" using fonts other than default */
        public static void POHMessage(Mobile from, int index)
        {
            Packet p = new AsciiMessage(from.Serial, from.Body, MessageType.Regular, MsgParams[index][0], MsgParams[index][1], from.Name, Msgs[index]);

            p.Acquire();
            foreach (NetState state in from.Map.GetClientsInRange(from.Location))
            {
                state.Send(p);
            }

            Packet.Release(p);
        }
Exemplo n.º 9
0
        public static void Broadcast(int hue, bool ascii, AccessLevel access, string text)
        {
            WorldBroadcastEventArgs e = new WorldBroadcastEventArgs(hue, ascii, access, text);

            EventSink.InvokeWorldBroadcast(e);

            hue    = e.Hue;
            ascii  = e.Ascii;
            text   = e.Text;
            access = e.Access;

            if (string.IsNullOrWhiteSpace(text))
            {
                return;
            }

            Packet p;

            if (ascii)
            {
                p = new AsciiMessage(Serial.MinusOne, -1, MessageType.Regular, hue, 3, "System", text);
            }
            else
            {
                p = new UnicodeMessage(Serial.MinusOne, -1, MessageType.Regular, hue, 3, "ENU", "System", text);
            }

            List <NetState> list = NetState.Instances;

            p.Acquire();

            for (var index = 0; index < list.Count; index++)
            {
                NetState s = list[index];

                if (s.Mobile != null && s.Mobile.AccessLevel >= access)
                {
                    s.Send(p);
                }
            }

            p.Release();

            NetState.FlushAll();
        }
Exemplo n.º 10
0
        public static void SendChatMessage(string from, string msg)
        {
            msg = "[" + from + "]: " + msg;
            Packet          p    = new AsciiMessage(Serial.MinusOne, -1, MessageType.Regular, Hue, 3, "System", msg);
            List <NetState> list = NetState.Instances;

            p.Acquire();

            for (int i = 0; i < list.Count; ++i)
            {
                if (list[i].Mobile != null && ((MythikPlayerMobile)list[i].Mobile).ChatEnabled)
                {
                    list[i].Send(p);
                }
            }
            p.Release();
            NetState.FlushAll();
        }
Exemplo n.º 11
0
        public override void sendMsg(IMessage message)
        {
            if (port == null || !port.IsOpen)
            {
                throw new DeviceNotConnectedException("tried to send data while the device is not connected!");
            }

            AsciiMessage m = message as AsciiMessage;

            log.Info("sending " + m.ToString());
            try
            {
                port.Write(m.asCharArray(), 0, m.asCharArray().Length);
            } catch (Exception e) {
                log.Error("error while reading data from port: \"" + getName() + "\"");
                throw e;
            }
        }
Exemplo n.º 12
0
        /*public static void Broadcast( int hue, bool ascii, string text ) {
         *      Packet p;
         *
         *      if ( ascii )
         *              p = new AsciiMessage( Serial.MinusOne, -1, MessageType.Regular, hue, 3, "System", text );
         *      else
         *              p = new UnicodeMessage( Serial.MinusOne, -1, MessageType.Regular, hue, 3, "ENU", "System", text );
         *
         *      List<NetState> list = NetState.Instances;
         *
         *      p.Acquire();
         *
         *      for ( int i = 0; i < list.Count; ++i ) {
         *              if ( list[i].Mobile != null )
         *                      list[i].Send( p );
         *      }
         *
         *      p.Release();
         *
         *      NetState.FlushAll();
         * }*/

        public static void Broadcast(int hue, bool ascii, string text)
        {
            Packet p;

            p = new AsciiMessage(Serial.MinusOne, -1, MessageType.Regular, hue, 0, "System", String.Format("System: {0}", text));

            List <NetState> list = NetState.Instances;

            p.Acquire();

            for (int i = 0; i < list.Count; ++i)
            {
                if (list[i].Mobile != null)
                {
                    list[i].Send(p);
                }
            }

            p.Release();

            NetState.FlushAll();
        }
Exemplo n.º 13
0
        public void TestAsciiMessage()
        {
            Serial serial      = (Serial)0x1024;
            var    graphic     = 0x100;
            var    messageType = MessageType.Label;
            var    hue         = 1024;
            var    font        = 3;
            var    name        = "Stuff";
            var    text        = "Some Text";

            var expected = new AsciiMessage(
                serial,
                graphic,
                messageType,
                hue,
                font,
                name,
                text
                ).Compile();

            var ns = PacketTestUtilities.CreateTestNetState();

            ns.SendMessage(
                serial,
                graphic,
                messageType,
                hue,
                font,
                true,
                null,
                name,
                text
                );

            var result = ns.SendPipe.Reader.TryRead();

            AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
        }
Exemplo n.º 14
0
        public static void Broadcast(int hue, bool ascii, string text)
        {
            Packet packet1;
            int    num1;

            if (ascii)
            {
                packet1 = new AsciiMessage(Serial.MinusOne, -1, MessageType.Regular, hue, 3, "System", text);
            }
            else
            {
                packet1 = new UnicodeMessage(Serial.MinusOne, -1, MessageType.Regular, hue, 3, "ENU", "System", text);
            }
            ArrayList list1 = NetState.Instances;

            for (num1 = 0; (num1 < list1.Count); ++num1)
            {
                if (((NetState)list1[num1]).Mobile != null)
                {
                    ((NetState)list1[num1]).Send(packet1);
                }
            }
        }
Exemplo n.º 15
0
        public void TestAsciiMessage()
        {
            Serial serial      = 0x1;
            var    graphic     = 0x100;
            var    messageType = MessageType.Label;
            var    hue         = 1024;
            var    font        = 3;
            var    name        = "Stuff";
            var    text        = "Some Text";

            var data = new AsciiMessage(
                serial,
                graphic,
                messageType,
                hue,
                font,
                name,
                text
                ).Compile();

            Span <byte> expectedData = stackalloc byte[45 + text.Length];
            var         pos          = 0;

            expectedData.Write(ref pos, (byte)0x1C);                  // Packet ID
            expectedData.Write(ref pos, (ushort)expectedData.Length); // Length

            expectedData.Write(ref pos, serial);
            expectedData.Write(ref pos, (ushort)graphic);
            expectedData.Write(ref pos, (byte)messageType);
            expectedData.Write(ref pos, (ushort)hue);
            expectedData.Write(ref pos, (ushort)font);
            expectedData.WriteAsciiFixed(ref pos, name, 30);
            expectedData.WriteAsciiNull(ref pos, text);

            AssertThat.Equal(data, expectedData);
        }