Пример #1
0
        public static void SendText(string text, Target target)
        {
            {
                if (BoltNetwork.isRunning)
                {
                    ChatEvent chatEvent = null;
                    switch (target)
                    {
                    case Target.OnlyServer:
                        chatEvent = ChatEvent.Create(GlobalTargets.OnlyServer);
                        break;

                    case Target.Everyone:
                        chatEvent = ChatEvent.Create(GlobalTargets.Everyone);
                        break;

                    case Target.Clients:
                        chatEvent = ChatEvent.Create(GlobalTargets.AllClients);
                        break;

                    case Target.Others:
                        chatEvent = ChatEvent.Create(GlobalTargets.Others);
                        break;

                    default:
                        break;
                    }
                    chatEvent.Message = text;
                    chatEvent.Sender  = ChatBoxMod.ModNetworkID;
                    chatEvent.Send();
                }
            }
        }
Пример #2
0
 private void SendLine(string line)
 {
     if (BoltNetwork.isRunning)
     {
         if (line[0] == '/')
         {
             line = line.Trim(new char[]
             {
                 ' ',
                 '/'
             });
             int num = line.IndexOf(' ');
             if (num == -1)
             {
                 CoopAdminCommand.Send(line, string.Empty);
             }
             else
             {
                 CoopAdminCommand.Send(line.Substring(0, num), line.Substring(num + 1, line.Length - (num + 1)));
             }
         }
         else
         {
             ChatEvent chatEvent = ChatEvent.Create(GlobalTargets.OnlyServer);
             chatEvent.Message = line;
             chatEvent.Sender  = LocalPlayer.Entity.networkId;
             chatEvent.Send();
         }
     }
 }
Пример #3
0
        private void SendChatMessage(string message)
        {
            ChatEvent c = ChatEvent.Create(GlobalTargets.AllClients);

            c.Message = message;
            c.Send();
        }
Пример #4
0
    private static void SendNetworkMessage(string message, BoltConnection source)
    {
        ChatEvent chatEvent = ChatEvent.Create(source);

        chatEvent.Message = message;
        chatEvent.Send();
    }
        public override void OnEvent(ChatEvent evnt)
        {
            if (!this.ValidateSender(evnt, global::SenderTypes.Any))
            {
                return;
            }
            if (evnt.Sender == NetworkChatMod.ModNetworkID)
            {
                return;
            }

            for (int i = 0; i < TheForest.Utils.Scene.SceneTracker.allPlayerEntities.Count; i++)
            {
                if (TheForest.Utils.Scene.SceneTracker.allPlayerEntities[i].source == evnt.RaisedBy)
                {
                    if (TheForest.Utils.Scene.SceneTracker.allPlayerEntities[i].networkId == evnt.Sender)
                    {
                        ChatEvent chatEvent = ChatEvent.Create(GlobalTargets.AllClients);
                        chatEvent.Sender  = evnt.Sender;
                        chatEvent.Message = evnt.Message;
                        chatEvent.Send();
                    }
                    return;
                }
            }
            if (BoltNetwork.isServer && evnt.RaisedBy == null)
            {
                ChatEvent chatEvent2 = ChatEvent.Create(GlobalTargets.AllClients);
                chatEvent2.Sender  = evnt.Sender;
                chatEvent2.Message = evnt.Message;
                chatEvent2.Send();
            }
        }
Пример #6
0
    private static void SendNetworkMessageAll(string message)
    {
        ChatEvent chatEvent = ChatEvent.Create(GlobalTargets.AllClients);

        chatEvent.Message = message;
        chatEvent.Sender  = CoopServerInfo.Instance.entity.networkId;
        chatEvent.Send();
    }
        private void sendChatMessage(NetworkId id, string message)
        {
            ChatEvent c = ChatEvent.Create(GlobalTargets.AllClients);

            c.Message = message;
            c.Sender  = id;
            c.Send();
        }
Пример #8
0
        /// <summary>
        /// Sends the specified message and prefix to the player
        /// </summary>
        /// <param name="message"></param>
        /// <param name="prefix"></param>
        /// <param name="args"></param>
        public void Message(string message, string prefix, params object[] args)
        {
            CoopServerInfo.Instance.entity.GetState <IPlayerState>().name = prefix != null ? prefix : "Server";
            var chatEvent = ChatEvent.Create(entity.source);

            chatEvent.Message = args.Length > 0 ? string.Format(Formatter.ToUnity(message), args) : Formatter.ToUnity(message);
            chatEvent.Sender  = CoopServerInfo.Instance.entity.networkId;
            chatEvent.Send();
        }
Пример #9
0
 private void SendLine(string line)
 {
     if (BoltNetwork.isRunning)
     {
         ChatEvent chatEvent = ChatEvent.Create(GlobalTargets.OnlyServer);
         chatEvent.Message = line;
         chatEvent.Sender  = LocalPlayer.Entity.networkId;
         chatEvent.Send();
     }
 }
Пример #10
0
 /// <summary>
 /// Sends bytes to targets, calls RecieveCommand on them
 /// </summary>
 /// <param name="bytearray">Bytes to send</param>
 /// <param name="target">Choose between possible recievers</param>
 public static void SendCommand(byte[] bytearray, GlobalTargets target)
 {
     if (BoltNetwork.isRunning)
     {
         ChatEvent chatEvent = ChatEvent.Create(target);
         chatEvent.Message = BytesToString(bytearray);
         chatEvent.Sender  = NetworkConfig.ModNetworkID;
         chatEvent.Send();
     }
 }
Пример #11
0
        /// <summary>
        /// Sends the specified message to the player
        /// </summary>
        /// <param name="message"></param>
        public void Message(string message)
        {
            CoopServerInfo.Instance.entity.GetState <IPlayerState>().name = "Server";

            var chatEvent = ChatEvent.Create(entity.source);

            chatEvent.Message = message;
            chatEvent.Sender  = CoopServerInfo.Instance.entity.networkId;
            chatEvent.Send();
            //CoopAdminCommand.SendNetworkMessage
        }
Пример #12
0
        /// <summary>
        /// Broadcasts the specified chat message and prefix to all players
        /// </summary>
        /// <param name="message"></param>
        /// <param name="prefix"></param>
        /// <param name="args"></param>
        public void Broadcast(string message, string prefix, params object[] args) // TODO: Fix NullReferenceException
        {
            //CoopServerInfo.Instance.entity.GetState<IPlayerState>().name = prefix ?? "Server";
            var chatEvent = ChatEvent.Create(GlobalTargets.AllClients);

            chatEvent.Message = args.Length > 0 ? string.Format(Formatter.ToUnity(message), args) : Formatter.ToUnity(message);
            chatEvent.Sender  = CoopServerInfo.Instance.entity.networkId;
            chatEvent.Send();

            Debug.Log($"[Chat] {message}");
        }
Пример #13
0
        public void BroadcastChat(string message)
        {
            if (!BoltNetwork.isRunning)
            {
                return;
            }

            var e = ChatEvent.Create(GlobalTargets.AllClients);

            e.Message = message;
            e.Sender  = LocalPlayer.Entity.networkId;
            e.Send();
        }
Пример #14
0
        /// <summary>
        /// Broadcasts a chat message
        /// </summary>
        /// <param name="id"></param>
        /// <param name="message"></param>
        public void BroadcastChat(NetworkId id, string message)
        {
            if (!BoltNetwork.isRunning)
            {
                return;
            }

            var e = ChatEvent.Create(GlobalTargets.AllClients);

            e.Message = message;
            e.Sender  = id;
            e.Send();
        }
Пример #15
0
        /// <summary>
        /// Broadcasts a chat message to all users
        /// </summary>
        /// <param name="message"></param>
        public void Broadcast(string message)
        {
            CoopServerInfo.Instance.entity.GetState <IPlayerState>().name = "Server";

            var chatEvent = ChatEvent.Create(GlobalTargets.AllClients);

            chatEvent.Message = message;
            chatEvent.Sender  = CoopServerInfo.Instance.entity.networkId;
            chatEvent.Send();
            //CoopServerInfo.Broadcast

            Debug.Log($"[Chat] {message}");
        }
Пример #16
0
 public static void SendLine(byte[] bytearray, BoltConnection con)
 {
     if (GameSetup.IsSinglePlayer || !BoltNetwork.isRunning)
     {
         RecieveLine(bytearray);
     }
     else
     {
         if (BoltNetwork.isRunning)
         {
             ChatEvent chatEvent = ChatEvent.Create(con);
             chatEvent.Message = EncodeCommand(bytearray);
             chatEvent.Sender  = ChatBoxMod.ModNetworkID;
             chatEvent.Send();
         }
     }
 }
Пример #17
0
 public static void SendLine(string s, BoltConnection con)
 {
     if (GameSetup.IsSinglePlayer || !BoltNetwork.isRunning)
     {
         RecieveLine(s);
     }
     else
     {
         if (BoltNetwork.isRunning)
         {
             ChatEvent chatEvent = ChatEvent.Create(con);
             chatEvent.Message = s;
             chatEvent.Sender  = ChatBoxMod.ModNetwokrID;
             chatEvent.Send();
         }
     }
 }
Пример #18
0
        public override void OnSubmit()
        {
            if (!string.IsNullOrEmpty(_input.value))
            {
                //Logger.Info("Trying to submit: {0}", _input.value);

                try
                {
                    if (!BoltNetwork.isRunning)
                    {
                        return;
                    }

                    // Check if player is detached
                    var detached = LocalPlayer.GameObject != null && LocalPlayer.GameObject.GetComponent <BoltEntity>() != null && !LocalPlayer.GameObject.GetComponent <BoltEntity>().isAttached;
                    if (detached)
                    {
                        // Pick a random player on the server
                        var player = Players.Keys.ToList().Shuffle()[0];

                        // Write with player name
                        var chatEvent = ChatEvent.Create(GlobalTargets.OnlyServer);
                        chatEvent.Message = "<ツ> " + _input.value;
                        chatEvent.Sender  = player;
                        chatEvent.Send();

                        // Display locally
                        AddLine(player, chatEvent.Message);
                    }
                    else
                    {
                        // Regular text sending
                        SendLine(_input.value);
                    }
                }
                catch (Exception e)
                {
                    Logger.Exception("Exception while trying to send message!", e);
                }

                _input.value = null;
            }
            _mustClose           = true;
            _lastInteractionTime = Time.time;
        }
Пример #19
0
        /// <summary>
        /// Broadcasts a chat message to all users
        /// </summary>
        /// <param name="message"></param>
        public void Broadcast(string message)
        {
            // Set the sender name to "Server"
            var player = new ChatBox.Player {
                _name = "Server", _color = Color.cyan
            };

            ChatBox.Instance.Players[LocalPlayer.Entity.networkId] = player;
            LocalPlayer.Entity.GetState <IPlayerState>().name      = "Server";

            // Create and send the chat event
            var chatEvent = ChatEvent.Create(GlobalTargets.Others);

            chatEvent.Message = message;
            chatEvent.Sender  = LocalPlayer.Entity.networkId;
            chatEvent.Send();

            Debug.Log($"[Broadcast] {message}");
        }
Пример #20
0
        /// <summary>
        /// Broadcasts a chat message
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="message"></param>
        public void BroadcastChat(BoltConnection connection, string message)
        {
            if (!BoltNetwork.isRunning)
            {
                return;
            }

            var player = Scene.SceneTracker.allPlayerEntities.FirstOrDefault(entity => entity.source.RemoteEndPoint.SteamId.Id == connection.RemoteEndPoint.SteamId.Id);

            if (!player)
            {
                return;
            }

            var e = ChatEvent.Create(GlobalTargets.AllClients);

            e.Message = message;
            e.Sender  = player.networkId;
            e.Send();
        }
Пример #21
0
        /// <summary>
        /// Sends a string to all players on the server
        /// </summary>
        /// <param name="s">Content of the message, make sure it ends with ';'</param>
        public static void SendLine(string s, Target target)
        {
            if (GameSetup.IsSinglePlayer || !BoltNetwork.isRunning)
            {
                RecieveLine(s);
            }
            else
            {
                if (BoltNetwork.isRunning)
                {
                    ChatEvent chatEvent = null;
                    switch (target)
                    {
                    case Target.OnlyServer:
                        chatEvent = ChatEvent.Create(GlobalTargets.OnlyServer);
                        break;

                    case Target.Everyone:
                        chatEvent = ChatEvent.Create(GlobalTargets.Everyone);
                        break;

                    case Target.Clinets:
                        chatEvent = ChatEvent.Create(GlobalTargets.AllClients);
                        break;

                    case Target.Others:
                        chatEvent = ChatEvent.Create(GlobalTargets.Others);
                        break;

                    default:
                        break;
                    }

                    chatEvent.Message = s;
                    chatEvent.Sender  = ChatBoxMod.ModNetwokrID;
                    chatEvent.Send();

                    Debug.Log("Sent: " + s);
                }
            }
        }
        public override void OnEvent(ChatEvent evnt)
        {
            //the host would resend all commands to the clients.
            //this is okay for chat messages
            //but with commands sent directly there is no need. This adds unnecessary latency.
            //additionally all events like experience after a kill would be proc twice for clients.


            if (!this.ValidateSender(evnt, global::SenderTypes.Any))
            {
                return;
            }
            if (evnt.Sender == ChatBoxMod.ModNetworkID)
            {
                return;
            }

            for (int i = 0; i < TheForest.Utils.Scene.SceneTracker.allPlayerEntities.Count; i++)
            {
                if (TheForest.Utils.Scene.SceneTracker.allPlayerEntities[i].source == evnt.RaisedBy)
                {
                    if (TheForest.Utils.Scene.SceneTracker.allPlayerEntities[i].networkId == evnt.Sender)
                    {
                        ChatEvent chatEvent = ChatEvent.Create(GlobalTargets.AllClients);
                        chatEvent.Sender  = evnt.Sender;
                        chatEvent.Message = evnt.Message;
                        chatEvent.Send();
                    }
                    return;
                }
            }
            if (BoltNetwork.isServer && evnt.RaisedBy == null)
            {
                ChatEvent chatEvent2 = ChatEvent.Create(GlobalTargets.AllClients);
                chatEvent2.Sender  = evnt.Sender;
                chatEvent2.Message = evnt.Message;
                chatEvent2.Send();
            }
        }
Пример #23
0
        public override void OnEvent(ChatEvent evnt)
        {
            if (evnt.Sender == NetworkConfig.ModNetworkID)
            {
                //Chat events work like this
                //Client sends a event to the host that a msg is sent;
                //The host broadcasts the message to everyone
                NetworkManager.RecieveCommand(NetworkManager.StringToBytes(evnt.Message));
                return;
            }

            if (!this.ValidateSender(evnt, global::SenderTypes.Any))
            {
                return;
            }

            for (int i = 0; i < TheForest.Utils.Scene.SceneTracker.allPlayerEntities.Count; i++)
            {
                if (TheForest.Utils.Scene.SceneTracker.allPlayerEntities[i].source == evnt.RaisedBy)
                {
                    if (TheForest.Utils.Scene.SceneTracker.allPlayerEntities[i].networkId == evnt.Sender)
                    {
                        ChatEvent chatEvent = ChatEvent.Create(GlobalTargets.AllClients);
                        chatEvent.Sender  = evnt.Sender;
                        chatEvent.Message = evnt.Message;
                        chatEvent.Send();
                    }
                    return;
                }
            }
            if (BoltNetwork.isServer && evnt.RaisedBy == null)
            {
                ChatEvent chatEvent2 = ChatEvent.Create(GlobalTargets.AllClients);
                chatEvent2.Sender  = evnt.Sender;
                chatEvent2.Message = evnt.Message;
                chatEvent2.Send();
            }
        }
Пример #24
0
        /// <summary>
        /// Sends a string to all players on the server
        /// </summary>
        /// <param name="s">Content of the message, make sure it ends with ';'</param>
        public static void SendLine(byte[] bytearray, Target target)
        {
            if (GameSetup.IsSinglePlayer || !BoltNetwork.isRunning)
            {
                RecieveLine(bytearray);
            }
            else
            {
                if (BoltNetwork.isRunning)
                {
                    ChatEvent chatEvent = null;
                    switch (target)
                    {
                    case Target.OnlyServer:
                        chatEvent = ChatEvent.Create(GlobalTargets.OnlyServer);
                        break;

                    case Target.Everyone:
                        chatEvent = ChatEvent.Create(GlobalTargets.Everyone);
                        break;

                    case Target.Clients:
                        chatEvent = ChatEvent.Create(GlobalTargets.AllClients);
                        break;

                    case Target.Others:
                        chatEvent = ChatEvent.Create(GlobalTargets.Others);
                        break;

                    default:
                        break;
                    }
                    chatEvent.Message = EncodeCommand(bytearray);
                    chatEvent.Sender  = ChatBoxMod.ModNetworkID;
                    chatEvent.Send();
                }
            }
        }
Пример #25
0
        public override void OnSubmit()
        {
            if (GriefClientPro.ChatManager == null)
            {
                base.OnSubmit();
                return;
            }

            // Create local event
            var chatEvent = new ChatManager.ChatEventArgs
            {
                Text = _input.value
            };

            // Process the event
            GriefClientPro.ChatManager.OnSubmit(chatEvent);

            if (!chatEvent.CustomHandler || string.IsNullOrEmpty(chatEvent.Text))
            {
                base.OnSubmit();
            }
            else
            {
                // Create the chat event
                var @event = ChatEvent.Create(chatEvent.Target);
                @event.Message = chatEvent.Text;
                @event.Sender  = chatEvent.SenderId;

                // Send the message
                PacketQueue.Add(@event);

                _input.value         = null;
                _mustClose           = true;
                _lastInteractionTime = Time.time;
            }
        }