Beispiel #1
0
        /// <summary>
        /// Clears loaded scripts
        /// </summary>
        private void ClearScripts()
        {
            // Ensure we clear whatever we have loaded
            LogIt("Clearing Scripts");
            ActiveScript?.Dispose();

            // Manually dispose
            foreach (var script in ScriptFiles)
            {
                script?.Dispose();
            }

            ScriptFiles.Clear();
            Dispatcher.BeginInvoke(new Action(() =>
            {
                ScriptList.ItemsSource   = null;
                FunctionList.ItemsSource = null;
                StringList.ItemsSource   = null;
                ImportList.ItemsSource   = null;
                IncludeList.ItemsSource  = null;
                Disassembly.Text         = "";
                Decompiler.Text          = "";
            }));
            LogIt("Scripts cleared");
        }
        public void Run()
        {
            try {
                switch (scriptLanguage)
                {
                case ScriptLanguage.JScript:
                    scriptEngine = new JScript();
                    break;

                case ScriptLanguage.VBScript:
                    scriptEngine = new VBScript();
                    break;

                default:
                    throw new ClrPlusException("Invalid Script Language");
                }
                EXCEPINFO info;
                ActiveScriptParse.InitNew();
                ActiveScript.SetScriptSite(this);

                // add this object in
                GlobalMembers.Add("WScript", this);

                foreach (string key in GlobalMembers.Keys)
                {
                    ActiveScript.AddNamedItem(key, ScriptItem.IsVisible | ScriptItem.GlobalMembers);
                }

                ActiveScriptParse.ParseScriptText(ScriptText, null, IntPtr.Zero, null, 0, 0, 0, IntPtr.Zero, out info);
                ActiveScript.SetScriptState((uint)ScriptState.Connected);
            } catch (Exception e) {
                Console.WriteLine(e.Message);
            }
        }
 public void Close()
 {
     if (null != scriptEngine)
     {
         ActiveScript.SetScriptState((uint)ScriptState.Disconnected);
         ActiveScript.Close();
     }
     scriptEngine = null;
 }
        public void Invoke(string functionName, params object[] args)
        {
            object dispatch;

            ActiveScript.GetScriptDispatch(null, out dispatch);
            var t = dispatch.GetType();

            t.InvokeMember(functionName, BindingFlags.InvokeMethod, null, dispatch, args);
        }
Beispiel #5
0
        public void Update()
        {
            foreach (OnlineScript ActiveScript in Host.ReadScripts())
            {
                ActiveScript.Execute(Host);
            }

            if (!Host.IsConnected())
            {
                OnConnectionLost();
            }
        }
            public override void ExecuteTrigger(int Index)
            {
                foreach (CutsceneActionScript ActiveScript in ListTextScriptToTrigger)
                {
                    for (int T = 0; T < ActiveScript.NameTriggers.Length; ++T)
                    {
                        ActiveScript.ExecuteTrigger(T);
                    }
                }

                IsActive = true;
            }
Beispiel #7
0
        public void Update()
        {
            CheckForNewClient();

            for (int C = ListPlayerClient.Count - 1; C >= 0; --C)
            {
                IOnlineConnection Sender = ListPlayerClient[C];

                foreach (OnlineScript ActiveScript in Sender.ReadScripts())
                {
                    ActiveScript.Execute(Sender);

                    SendToClients(ActiveScript, Sender);
                }
            }
        }
Beispiel #8
0
        public void Update()
        {
            foreach (OnlineScript ActiveScript in Host.ReadScripts())
            {
                ActiveScript.Execute(Host);
            }

            foreach (CommunicationClient ActiveGroup in DicCrossServerCommunicationByGroupID.Values)
            {
                ActiveGroup.Update();
            }

            if (!Host.IsConnected())
            {
                OnConnectionLost();
            }
        }
Beispiel #9
0
        private void Update()
        {
            while (!CancelToken.IsCancellationRequested)
            {
                WaitForConnections();

                if (Master != null)
                {
                    foreach (OnlineScript ActiveScript in Master.ReadScripts())
                    {
                        ActiveScript.Execute(Master);
                    }
                }
            }

            ClientsListener.Stop();
            ClientsListener = null;

            MastersListener.Stop();
            MastersListener = null;
        }
        // ReSharper disable InconsistentNaming

        public void Quit(int i)
        {
            returnValue = i;
            ActiveScript.SetScriptState((uint)ScriptState.Disconnected);
        }
        public void UpdatePlayers()
        {
            Parallel.ForEach(ListPlayer, (ActivePlayer, loopState) =>
            {
                if (!ActivePlayer.IsConnected())
                {
                    if (ActivePlayer.HasLeftServer())
                    {
                        ListPlayerToRemove.Add(ActivePlayer);
                        Database.RemovePlayer(ActivePlayer);
                    }
                }
                else
                {
                    lock (ActivePlayer.ListAsyncOnlineScript)
                    {
                        foreach (OnlineScript ActiveScript in ActivePlayer.ListAsyncOnlineScript)
                        {
                            ActiveScript.Execute(ActivePlayer);
                        }

                        ActivePlayer.ListAsyncOnlineScript.Clear();
                    }
                }
            });

            while (ListPlayerToRemove.Count > 0)
            {
                ListPlayer.Remove(ListPlayerToRemove[0]);
                ListPlayerToRemove.RemoveAt(0);
            }

            Parallel.ForEach(DicLocalRoom.Values, (ActiveGroup, loopState) =>
            {
                if (ActiveGroup.IsRunningSlow())
                {
                    //Send Room to another Server
                }

                if (ActiveGroup.CurrentGame != null)
                {
                    ActiveGroup.CurrentGame.Update(DeltaTime);
                }

                for (int P = ActiveGroup.Room.ListOnlinePlayer.Count - 1; P >= 0; --P)
                {
                    IOnlineConnection ActivePlayer = ActiveGroup.Room.ListOnlinePlayer[P];

                    if (!ActivePlayer.IsConnected())
                    {
                        if (ActivePlayer.HasLeftServer())
                        {
                            string PlayerID = ActiveGroup.Room.ListOnlinePlayer[P].ID;
                            ActiveGroup.Room.RemoveOnlinePlayer(P);
                            Database.UpdatePlayerCountInRoom(ActiveGroup.Room.RoomID, (byte)ActiveGroup.Room.ListOnlinePlayer.Count);

                            if (ActiveGroup.Room.ListOnlinePlayer.Count == 0)
                            {
                                ListLocalRoomToRemove.Add(ActiveGroup.Room.RoomID);
                            }

                            if (ActiveGroup.CurrentGame == null)
                            {
                                foreach (IOnlineConnection OtherPlayer in ActiveGroup.Room.ListOnlinePlayer)
                                {
                                    OtherPlayer.Send(new PlayerLeftScriptServer(PlayerID, 0));
                                }
                            }
                            else
                            {
                                ActiveGroup.CurrentGame.RemoveOnlinePlayer(PlayerID, ActivePlayer);
                            }

                            ActivePlayer.StopReadingScriptAsync();
                        }
                    }
                    else
                    {
                        lock (ActivePlayer.ListAsyncOnlineScript)
                        {
                            foreach (OnlineScript ActiveScript in ActivePlayer.ListAsyncOnlineScript)
                            {
                                ActiveScript.Execute(ActivePlayer);
                            }

                            ActivePlayer.ListAsyncOnlineScript.Clear();
                        }
                    }
                }
            });

            while (ListLocalRoomToRemove.Count > 0)
            {
                DicLocalRoom.Remove(ListLocalRoomToRemove[0]);
                DicAllRoom.Remove(ListLocalRoomToRemove[0]);
                Database.RemoveRoom(ListLocalRoomToRemove[0]);
                ListLocalRoomToRemove.RemoveAt(0);
            }

            foreach (GameClientGroup ActiveGroup in DicTransferingRoom.Values)
            {
                foreach (IOnlineConnection ActivePlayer in ActiveGroup.Room.ListOnlinePlayer)
                {
                    lock (ActivePlayer.ListAsyncOnlineScript)
                    {
                        foreach (OnlineScript ActiveScript in ActivePlayer.ListAsyncOnlineScript)
                        {
                            ActiveScript.Execute(ActivePlayer);
                        }

                        ActivePlayer.ListAsyncOnlineScript.Clear();
                    }
                }

                if (ActiveGroup.Room.ListOnlinePlayer.Count == ActiveGroup.Room.CurrentPlayerCount && ActiveGroup.CurrentGame != null)
                {
                    ListTransferingRoomToRemove.Add(ActiveGroup.Room.RoomID);
                }
            }

            while (ListTransferingRoomToRemove.Count > 0)
            {
                DicLocalRoom.Add(ListTransferingRoomToRemove[0], DicTransferingRoom[ListTransferingRoomToRemove[0]]);
                DicTransferingRoom.Remove(ListTransferingRoomToRemove[0]);
                ListTransferingRoomToRemove.RemoveAt(0);
            }

            //TODO: Run task in background
            if (DateTimeOffset.Now > NextRoomUpdateTime)
            {
                NextRoomUpdateTime = NextRoomUpdateTime.AddSeconds(10);

                List <IRoomInformations> ListRoomUpdates = Database.GetAllRoomUpdatesSinceLastTimeChecked(ServerVersion);

                if (ListRoomUpdates != null)
                {
                    foreach (IRoomInformations ActiveRoomUpdate in ListRoomUpdates)
                    {
                        if (ActiveRoomUpdate.IsDead)
                        {
                            DicAllRoom.Remove(ActiveRoomUpdate.RoomID);
                        }
                        else
                        {
                            if (DicAllRoom.ContainsKey(ActiveRoomUpdate.RoomID))
                            {
                                DicAllRoom[ActiveRoomUpdate.RoomID] = ActiveRoomUpdate;
                            }
                            else
                            {
                                DicAllRoom.Add(ActiveRoomUpdate.RoomID, ActiveRoomUpdate);
                            }
                        }
                    }

                    SharedWriteBuffer.ClearWriteBuffer();
                    SharedWriteBuffer.WriteScript(new RoomListScriptServer(this, ListRoomUpdates));
                    Parallel.ForEach(ListPlayer, (ActivePlayer, loopState) =>
                    {
                        ActivePlayer.SendWriteBuffer();
                    });
                }
            }
        }
Beispiel #12
0
        public void UpdatePlayers()
        {
            Parallel.ForEach(ListPlayerConnection, (ActivePlayer, loopState) =>
            {
                if (!ActivePlayer.IsConnected())
                {
                    if (ActivePlayer.HasLeftServer())
                    {
                        ListPlayerToRemove.Add(new KeyValuePair <IOnlineConnection, string>(ActivePlayer, null));
                        Database.RemovePlayer(ActivePlayer);
                    }
                }
                else
                {
                    lock (ActivePlayer.ListAsyncOnlineScript)
                    {
                        foreach (OnlineScript ActiveScript in ActivePlayer.ListAsyncOnlineScript)
                        {
                            ActiveScript.Execute(ActivePlayer);
                        }

                        ActivePlayer.ListAsyncOnlineScript.Clear();
                    }
                }
            });

            while (ListPlayerToRemove.Count > 0)
            {
                DicCommunicationGroup[ListPlayerToRemove[0].Value].ListGroupMember.Remove(ListPlayerToRemove[0].Key);
                DicPlayerInfoByName.Remove(ListPlayerToRemove[0].Key.ID);
                DicPlayerByID.Remove(ListPlayerToRemove[0].Key.ID);
                ListPlayerToRemove.RemoveAt(0);
            }

            Parallel.ForEach(DicCommunicationGroup.Values, (ActiveGroup, loopState) =>
            {
                if (ActiveGroup.IsRunningSlow())
                {
                    //Send Room to another Server
                }

                for (int P = ActiveGroup.ListGroupMember.Count - 1; P >= 0; --P)
                {
                    IOnlineConnection ActivePlayer = ActiveGroup.ListGroupMember[P];

                    if (!ActivePlayer.IsConnected())
                    {
                        if (ActivePlayer.HasLeftServer())
                        {
                            string PlayerID = ActiveGroup.ListGroupMember[P].ID;
                            ActiveGroup.RemoveOnlinePlayer(P);

                            if (ActiveGroup.ListGroupMember.Count == 0)
                            {
                                ListGroupToRemove.Add(ActiveGroup.GroupID);
                            }

                            ActivePlayer.StopReadingScriptAsync();
                        }
                    }
                }
            });

            while (ListGroupToRemove.Count > 0)
            {
                DicCommunicationGroup.Remove(ListGroupToRemove[0]);

                ListGroupToRemove.RemoveAt(0);
            }

            if (DateTimeOffset.Now > NextPlayerUpdateTime)
            {
                NextPlayerUpdateTime = NextPlayerUpdateTime.AddSeconds(10);

                SharedWriteBuffer.ClearWriteBuffer();
                SharedWriteBuffer.WriteScript(new PlayerListScriptServer(GetPlayerNames()));

                Parallel.ForEach(DicCommunicationGroup["Global"].ListGroupMember, (ActiveMember, loopState) =>
                {
                    ActiveMember.SendWriteBuffer();
                });
            }
        }