コード例 #1
0
        public GameEngine(Game def, string nickname, bool isLocal = false)
        {
            IsLocal     = isLocal;
            _definition = def;
            _table      = new Table(def.Table);
            Variables   = new Dictionary <string, int>();
            foreach (var varDef in def.Variables.Where(v => v.Global))
            {
                Variables.Add(varDef.Name, varDef.Default);
            }
            GlobalVariables = new Dictionary <string, string>();
            foreach (var varDef in def.GlobalVariables)
            {
                GlobalVariables.Add(varDef.Name, varDef.DefaultValue);
            }

            nick = nickname;
            while (String.IsNullOrWhiteSpace(nick))
            {
                nick = Prefs.Nickname;
                if (string.IsNullOrWhiteSpace(nick))
                {
                    nick = Skylabs.Lobby.Randomness.GrabRandomNounWord() + new Random().Next(30);
                }
                var retNick = nick;
                Program.Dispatcher.Invoke(new Action(() =>
                {
                    var i   = new InputDlg("Choose a nickname", "Choose a nickname", nick);
                    retNick = i.GetString();
                }));
                nick = retNick;
            }
        }
コード例 #2
0
        private void NewFolderClick(object sender, RoutedEventArgs e)
        {
            if (SelectedList == null)
            {
                return;
            }
            var id   = new InputDlg("Create a New Folder", "Please enter a folder name", "");
            var name = id.GetString();

            if (String.IsNullOrWhiteSpace(name))
            {
                return;
            }
            try
            {
                var path = Path.Combine(SelectedList.Path, name);
                Directory.CreateDirectory(path);
                SelectedList.DeckLists.Add(new DeckList(path, this.Dispatcher, SelectedList, false));
            }
            catch (Exception ex)
            {
                Log.Warn("NewFolderClick", ex);
                TopMostMessageBox.Show(
                    "This folder name is invalid.",
                    "Invalid",
                    MessageBoxButton.OK,
                    MessageBoxImage.Information);
            }
        }
コード例 #3
0
        private void RenameFolderClick(object sender, RoutedEventArgs e)
        {
            if (SelectedList == null)
            {
                return;
            }
            var id   = new InputDlg("Rename Folder", "Please enter a new folder name", "");
            var name = id.GetString();

            if (String.IsNullOrWhiteSpace(name))
            {
                return;
            }
            try
            {
                var di      = new DirectoryInfo(SelectedList.Path);
                var newPath = Path.Combine(di.Parent.FullName, name);
                Directory.Move(SelectedList.Path, newPath);
                var parent = SelectedList.Parent;
                parent.DeckLists.Remove(SelectedList);
                parent.DeckLists.Add(new DeckList(newPath, this.Dispatcher, parent));
            }
            catch (Exception ex)
            {
                Log.Warn("RenameFolderClick", ex);
                TopMostMessageBox.Show(
                    "This folder name is invalid.",
                    "Invalid",
                    MessageBoxButton.OK,
                    MessageBoxImage.Information);
            }
        }
コード例 #4
0
ファイル: GameEngine.cs プロジェクト: saturnattack/OCTGN
        public GameEngine(Game def, string nickname, string password = "", bool isLocal = false)
        {
            IsLocal       = isLocal;
            this.Password = password;
            _definition   = def;
            _table        = new Table(def.Table);
            Variables     = new Dictionary <string, int>();
            foreach (var varDef in def.Variables.Where(v => v.Global))
            {
                Variables.Add(varDef.Name, varDef.Default);
            }
            GlobalVariables = new Dictionary <string, string>();
            foreach (var varDef in def.GlobalVariables)
            {
                GlobalVariables.Add(varDef.Name, varDef.DefaultValue);
            }

            this.Nickname = nickname;
            while (String.IsNullOrWhiteSpace(this.Nickname))
            {
                this.Nickname = Prefs.Nickname;
                if (string.IsNullOrWhiteSpace(this.Nickname))
                {
                    this.Nickname = Skylabs.Lobby.Randomness.GrabRandomNounWord() + new Random().Next(30);
                }
                var retNick = this.Nickname;
                Program.Dispatcher.Invoke(new Action(() =>
                {
                    var i   = new InputDlg("Choose a nickname", "Choose a nickname", this.Nickname);
                    retNick = i.GetString();
                }));
                this.Nickname = retNick;
            }
            // Load all game markers
            foreach (DataNew.Entities.Marker m in Definition.GetAllMarkers())
            {
                if (!_markersById.ContainsKey(m.Id))
                {
                    _markersById.Add(m.Id, m);
                }
            }
            // Init fields
            CurrentUniqueId = 1;
            TurnNumber      = 0;
            TurnPlayer      = null;

            CardFrontBitmap = ImageUtils.CreateFrozenBitmap(Definition.GetCardFrontUri());
            CardBackBitmap  = ImageUtils.CreateFrozenBitmap(Definition.GetCardBackUri());
            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                // Create the global player, if any
                if (Definition.GlobalPlayer != null)
                {
                    Play.Player.GlobalPlayer = new Play.Player(Definition);
                }
                // Create the local player
                Play.Player.LocalPlayer = new Play.Player(Definition, this.Nickname, 255, Crypto.ModExp(Program.PrivateKey));
            }));
        }
コード例 #5
0
ファイル: Script_3_1_0_0.cs プロジェクト: wlk0/OCTGN
 public string AskString(string question, string defaultValue)
 {
     return(QueueAction <string>(() =>
     {
         var dlg = new InputDlg("Question", question, defaultValue);
         var result = dlg.GetString();
         return dlg.DialogResult.GetValueOrDefault() ? result : null;
     }));
 }
コード例 #6
0
ファイル: Script_3_1_0_1.cs プロジェクト: rerbes/OCTGN
 public int?AskInteger(string question, int defaultValue)
 {
     return(QueueAction <int?>(() =>
     {
         var dlg = new InputDlg("Question", question,
                                defaultValue.ToString(
                                    CultureInfo.InvariantCulture));
         int result = dlg.GetPositiveInt();
         return dlg.DialogResult.GetValueOrDefault() ? result : (int?)null;
     }));
 }
コード例 #7
0
        private void StartJoinGame(HostedGameViewModel hostedGame, DataNew.Entities.Game game, bool spectate)
        {
            if (hostedGame.GameSource == "Online")
            {
                var client = new Octgn.Site.Api.ApiClient();
                if (!client.IsGameServerRunning(Program.LobbyClient.Username, Program.LobbyClient.Password))
                {
                    throw new UserMessageException("The game server is currently down. Please try again later.");
                }
            }
            Log.InfoFormat("Starting to join a game {0} {1}", hostedGame.GameId, hostedGame.Name);
            Program.IsHost        = false;
            Program.IsMatchmaking = false;
            var password = "";

            if (hostedGame.HasPassword)
            {
                Dispatcher.Invoke(new Action(() =>
                {
                    var dlg  = new InputDlg("Password", "Please enter this games password", "");
                    password = dlg.GetString();
                }));
            }
            var username = (Program.LobbyClient.IsConnected == false ||
                            Program.LobbyClient.Me == null ||
                            Program.LobbyClient.Me.UserName == null) ? Prefs.Nickname : Program.LobbyClient.Me.UserName;

            Program.GameEngine            = new GameEngine(game, username, spectate, password);
            Program.CurrentOnlineGameName = hostedGame.Name;
            IPAddress hostAddress = hostedGame.IPAddress;

            if (hostAddress == null)
            {
                Log.WarnFormat("Dns Error, couldn't resolve {0}", AppConfig.GameServerPath);
                throw new UserMessageException("There was a problem with your DNS. Please try again.");
            }

            try
            {
                Log.InfoFormat("Creating client for {0}:{1}", hostAddress, hostedGame.Port);
                Program.Client = new ClientSocket(hostAddress, hostedGame.Port);
                Log.InfoFormat("Connecting client for {0}:{1}", hostAddress, hostedGame.Port);
                Program.Client.Connect();
            }
            catch (Exception e)
            {
                Log.Warn("Start join game error ", e);
                throw new UserMessageException("Could not connect. Please try again.");
            }
        }
コード例 #8
0
ファイル: FirstRunDialog.cs プロジェクト: zgren/dp2
        private void button_finish_Click(object sender, EventArgs e)
        {
            string strError = "";

            if (this.comboBox_server_serverType.Text == "[暂时不使用任何服务器]")
            {
                goto END1;
            }

            if (string.IsNullOrEmpty(this.textBox_server_dp2LibraryServerUrl.Text) == true)
            {
                strError = "请输入 dp2library 服务器 URL 地址";
                goto ERROR1;
            }

            if (string.IsNullOrEmpty(this.textBox_server_userName.Text) == true)
            {
                strError = "请输入 用户名";
                goto ERROR1;
            }

            int nRet = TestConnectServer(out strError);

            if (nRet == -1)
            {
                goto ERROR1;
            }

            if (this.comboBox_server_serverType.Text == "其它服务器" ||
                string.IsNullOrEmpty(this.comboBox_server_serverType.Text) == true)
            {
                string strServerName = InputDlg.GetInput(this,
                                                         "请给这个服务器取一个便于识别的名字",
                                                         "[请给这个服务器取一个便于识别的名字]\r\n服务器名:", "新服务器", this.Font);
                if (strServerName != null)
                {
                    // this.comboBox_server_serverType.Text = strServerName;
                    this.ServerName = strServerName;
                }
            }

END1:
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
            return;

ERROR1:
            MessageBox.Show(this, strError);
        }
コード例 #9
0
ファイル: ChatForm.cs プロジェクト: zgren/dp2
        void menu_newGroupName_Click(object sender, EventArgs e)
        {
            var name = InputDlg.GetInput(this,
                                         "添加群名",
                                         "群名",
                                         "",
                                         this.Font);

            if (name == null)
            {
                return;
            }

            AddNewRow(name, "");
        }
コード例 #10
0
ファイル: InputItemBarcodeDialog.cs プロジェクト: zszqwe/dp2
        // 重设价格
        void menu_modifyPrice_Click(object sender, EventArgs e)
        {
            string strNewPrice = InputDlg.GetInput(
                this,
                "重设选定的事项的价格",
                "价格: ",
                "",
                this.Font);

            if (strNewPrice == null)
            {
                return;
            }

            foreach (ListViewItem item in this.listView_barcodes.SelectedItems)
            {
                // ListViewItem item = this.listView_barcodes.SelectedItems[i];
                ListViewUtil.ChangeItemText(item, COLUMN_PRICE, strNewPrice);
            }
        }
コード例 #11
0
        public Game(GameDef def, bool isLocal = false)
        {
            IsLocal     = isLocal;
            _definition = def;
            _table      = new Table(def.TableDefinition);
            Variables   = new Dictionary <string, int>();
            foreach (VariableDef varDef in def.Variables.Where(v => v.Global))
            {
                Variables.Add(varDef.Name, varDef.DefaultValue);
            }
            GlobalVariables = new Dictionary <string, string>();
            foreach (GlobalVariableDef varDef in def.GlobalVariables)
            {
                GlobalVariables.Add(varDef.Name, varDef.DefaultValue);
            }

            if (IsLocal)
            {
                var i = new InputDlg("Choose a nickname", "Choose a nickname",
                                     "User" + new Random().Next().ToString(CultureInfo.InvariantCulture));
                var ret = i.GetString();
                if (ret == "")
                {
                    ret = "User" + new Random().Next().ToString(CultureInfo.InvariantCulture);
                }
                nick = ret;
            }
            else
            {
                if (Program.LobbyClient == null || Program.LobbyClient.Me == null)
                {
                    nick = "User" + new Random().Next().ToString(CultureInfo.InvariantCulture);
                }
                else
                {
                    nick = Program.LobbyClient.Me.User.User;
                }
            }
        }
コード例 #12
0
        private void MenuItem_readConfig_Click(object sender, EventArgs e)
        {
            string strError = "";
            string strCfgNo = InputDlg.GetInput(this, "", "cfg_no", "0");

            if (strCfgNo == null)
            {
                return;
            }
            if (uint.TryParse(strCfgNo, out uint cfg_no) == false)
            {
                strError = $"cfg_no '{strCfgNo}' 不合法";
                goto ERROR1;
            }
            ReadConfigResult result = _driver.ReadConfig("*", cfg_no);

            MessageDlg.Show(this, $"cfg_no:{result.CfgNo}\r\nbytes:\r\n{Element.GetHexString(result.Bytes, "4")}", "config info");
            return;

ERROR1:
            MessageBox.Show(this, strError);
        }
コード例 #13
0
        private void button_add_Click(object sender, EventArgs e)
        {
            string result = InputDlg.GetInput(this,
                                              "添加普通号码",
                                              "号码:",
                                              "",
                                              this.Font);

            if (result == null)
            {
                return;
            }
            // 查重
            if (this.listBox1.Items.IndexOf(result) == -1)
            {
                this.listBox1.Items.Add(result);
                this.listBox1.SelectedItem = result;
            }
            else
            {
                MessageBox.Show(this, $"号码 {result} 已经存在了");
            }
        }
コード例 #14
0
    // 维护102对照关系
    void Manage102()
    {
        string strError = "";
        string strISBN  = "";
        int    nRet     = 0;

        strISBN = this.DetailForm.MarcEditor.Record.Fields.GetFirstSubfield("010", "a").Trim();

        string strPublisherNumber = "";

        if (String.IsNullOrEmpty(strISBN) == false)
        {
            // 切割出 出版社 代码部分
            nRet = this.DetailForm.MainForm.GetPublisherNumber(strISBN,
                                                               out strPublisherNumber,
                                                               out strError);
            if (nRet == -1)
            {
                goto ERROR1;
            }
        }

        if (String.IsNullOrEmpty(strPublisherNumber) == true)
        {
            strPublisherNumber = "978-7-?";
        }

        strPublisherNumber = InputDlg.GetInput(
            this.DetailForm,
            "维护102对照表 -- 第1步",
            "请输入ISBN中出版社号码部分:",
            strPublisherNumber);
        if (strPublisherNumber == null)
        {
            return;     // 放弃整个操作
        }
        string strValue = "";

        nRet = this.DetailForm.Get102Info(strPublisherNumber,
                                          out strValue,
                                          out strError);
        if (nRet == -1)
        {
            goto ERROR1;
        }

        if (nRet == 0 || strValue == "")
        {
            strValue = "国家代码[2位]:城市代码[6位]";
        }

        // 创建新条目
        strValue = InputDlg.GetInput(
            this.DetailForm,
            "维护102对照表 -- 第2步",
            "请输入ISBN出版社号码 '" + strPublisherNumber + "' 对应的UNIMARC 102$a$b参数(格式国家代码[2位]:城市代码[6位]):",
            strValue);
        if (strValue == null)
        {
            return;     // 放弃整个操作
        }
        if (strValue == "")
        {
            goto DOSAVE;
        }

        // MessageBox.Show(this.DetailForm, strValue);

        // 把全角冒号替换为半角的形态
        strValue = strValue.Replace(":", ":");

        string strCountryCode = "";
        string strCityCode    = "";

        nRet = strValue.IndexOf(":");
        if (nRet == -1)
        {
            strCountryCode = strValue;

            if (strCountryCode.Length != 2)
            {
                strError = "国家代码 '" + strCountryCode + "' 应当为2字符";
                goto ERROR1;
            }
        }
        else
        {
            strCountryCode = strValue.Substring(0, nRet);
            strCityCode    = strValue.Substring(nRet + 1);
            if (strCountryCode.Length != 2)
            {
                strError = "冒号前面的国家代码部分 '" + strCountryCode + "' 应当为2字符";
                goto ERROR1;
            }
            if (strCityCode.Length != 6)
            {
                strError = "冒号后面的城市代码部分 '" + strCityCode + "' 应当为6字符";
                goto ERROR1;
            }
        }

        strValue = strCountryCode + ":" + strCityCode;

DOSAVE:
        nRet = this.DetailForm.Set102Info(strPublisherNumber,
                                          strValue,
                                          out strError);
        if (nRet == -1)
        {
            goto ERROR1;
        }
        return;

ERROR1:
        MessageBox.Show(this.DetailForm, strError);
    }
コード例 #15
0
ファイル: GameEngine.cs プロジェクト: seurimas/OCTGN
        public GameEngine(Game def, string nickname, bool specator, string password = "", bool isLocal = false)
        {
            Spectator = specator;
            Program.GameMess.Clear();
            if (Versioned.ValidVersion(def.ScriptVersion) == false)
            {
                Program.GameMess.Warning(
                    "Can't find API v{0}. Loading the latest version.\n\nIf you have problems, get in contact of the developer of the game to get an update.\nYou can get in contact of them here {1}",
                    def.ScriptVersion, def.GameUrl);
                def.ScriptVersion = Versioned.LatestVersion;
            }
            //Program.ChatLog.ClearEvents();
            IsLocal       = isLocal;
            this.Password = password;
            _definition   = def;
            _table        = new Table(def.Table);
            Variables     = new Dictionary <string, int>();
            foreach (var varDef in def.Variables.Where(v => v.Global))
            {
                Variables.Add(varDef.Name, varDef.Default);
            }
            GlobalVariables = new Dictionary <string, string>();
            foreach (var varDef in def.GlobalVariables)
            {
                GlobalVariables.Add(varDef.Name, varDef.DefaultValue);
            }
            ScriptApi     = Versioned.Get <ScriptApi>(Definition.ScriptVersion);
            this.Nickname = nickname;
            while (String.IsNullOrWhiteSpace(this.Nickname))
            {
                this.Nickname = Prefs.Nickname;
                if (string.IsNullOrWhiteSpace(this.Nickname))
                {
                    this.Nickname = Skylabs.Lobby.Randomness.GrabRandomNounWord() + new Random().Next(30);
                }
                var retNick = this.Nickname;
                Program.Dispatcher.Invoke(new Action(() =>
                {
                    var i   = new InputDlg("Choose a nickname", "Choose a nickname", this.Nickname);
                    retNick = i.GetString();
                }));
                this.Nickname = retNick;
            }
            // Load all game markers
            foreach (DataNew.Entities.Marker m in Definition.GetAllMarkers())
            {
                if (!_markersById.ContainsKey(m.Id))
                {
                    _markersById.Add(m.Id, m);
                }
            }
            // Init fields
            CurrentUniqueId = 1;
            TurnNumber      = 0;
            TurnPlayer      = null;

            foreach (var size in Definition.CardSizes)
            {
                var front = ImageUtils.CreateFrozenBitmap(new Uri(size.Value.Front));
                var back  = ImageUtils.CreateFrozenBitmap(new Uri(size.Value.Back));
                _cardFrontsBacksCache.Add(size.Key, new Tuple <BitmapImage, BitmapImage>(front, back));
            }
            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                // clear any existing players
                Play.Player.All.Clear();
                Player.Spectators.Clear();
                // Create the global player, if any
                if (Definition.GlobalPlayer != null)
                {
                    Play.Player.GlobalPlayer = new Play.Player(Definition);
                }
                // Create the local player
                Play.Player.LocalPlayer = new Play.Player(Definition, this.Nickname, 255, Crypto.ModExp(Prefs.PrivateKey), specator, true);
            }));
        }
コード例 #16
0
ファイル: InputItemBarcodeDialog.cs プロジェクト: zszqwe/dp2
        // 附加折扣
        void menu_appendDiscount_Click(object sender, EventArgs e)
        {
            string strError = "";

            string strDiscountPart = InputDlg.GetInput(
                this,
                "为已有的价格字符串附加折扣部分",
                "折扣: ",
                this.UsedDiscountString,
                this.Font);

            if (strDiscountPart == null)
            {
                return;
            }

            strDiscountPart = strDiscountPart.Trim();

            if (string.IsNullOrEmpty(strDiscountPart) == true)
            {
                strError = "所输入的折扣部分为空,放弃处理";
                goto ERROR1;
            }

            if (strDiscountPart[0] == '*')
            {
                strDiscountPart = strDiscountPart.Substring(1).Trim();
            }

            if (string.IsNullOrEmpty(strDiscountPart) == true)
            {
                strError = "所输入的折扣部分的有效部分为空,放弃处理";
                goto ERROR1;
            }

            this.UsedDiscountString = strDiscountPart;  // 记忆

            foreach (ListViewItem item in this.listView_barcodes.SelectedItems)
            {
                // ListViewItem item = this.listView_barcodes.SelectedItems[i];
                string strOldPrice = ListViewUtil.GetItemText(item, COLUMN_PRICE);
                if (string.IsNullOrEmpty(strOldPrice) == true)
                {
                    strError = "第 " + (this.listView_barcodes.Items.IndexOf(item) + 1).ToString() + " 个事项价格部分为空,无法附加折扣部分。操作中断";
                    goto ERROR1;
                }

                int nRet = strOldPrice.IndexOf("*");
                if (nRet != -1)
                {
                    strOldPrice = strOldPrice.Substring(0, nRet).Trim();
                }

                strOldPrice += "*" + strDiscountPart;

                ListViewUtil.ChangeItemText(item, COLUMN_PRICE, strOldPrice);
            }
            return;

ERROR1:
            MessageBox.Show(this, strError);
        }
コード例 #17
0
    void Add102()
    {
        string strError = "";
        string strISBN  = "";
        int    nRet     = 0;

        strISBN = this.DetailForm.MarcEditor.Record.Fields.GetFirstSubfield("010", "a");

        if (strISBN.Trim() == "")
        {
            strError = "记录中不存在010$a子字段,因此无法加102$a$b";
            goto ERROR1;
        }

        // 切割出 出版社 代码部分
        string strPublisherNumber = "";

        nRet = this.DetailForm.MainForm.GetPublisherNumber(strISBN,
                                                           out strPublisherNumber,
                                                           out strError);
        if (nRet == -1)
        {
            goto ERROR1;
        }

        string strValue = "";

        nRet = this.DetailForm.Get102Info(strPublisherNumber,
                                          out strValue,
                                          out strError);
        if (nRet == -1)
        {
            goto ERROR1;
        }

        if (nRet == 0 || strValue == "")
        {
            // 创建新条目
            strValue = InputDlg.GetInput(
                this.DetailForm,
                null,
                "请输入ISBN出版社号码 '" + strISBN + "' 对应的UNIMARC 102$a$b参数(格式 国家代码[2位]:城市代码[6位]):",
                "国家代码[2位]:城市代码[6位]");
            if (strValue == null)
            {
                return; // 放弃整个操作
            }
            nRet = this.DetailForm.Set102Info(strPublisherNumber,
                                              strValue,
                                              out strError);
            if (nRet == -1)
            {
                goto ERROR1;
            }
        }

        // MessageBox.Show(this.DetailForm, strValue);

        // 把全角冒号替换为半角的形态
        strValue = strValue.Replace(":", ":");

        string strCountryCode = "";
        string strCityCode    = "";

        nRet = strValue.IndexOf(":");
        if (nRet == -1)
        {
            strCountryCode = strValue;

            if (strCountryCode.Length != 2)
            {
                strError = "国家代码 '" + strCountryCode + "' 应当为2字符";
                goto ERROR1;
            }
        }
        else
        {
            strCountryCode = strValue.Substring(0, nRet);
            strCityCode    = strValue.Substring(nRet + 1);
            if (strCountryCode.Length != 2)
            {
                strError = "冒号前面的国家代码部分 '" + strCountryCode + "' 应当为2字符";
                goto ERROR1;
            }
            if (strCityCode.Length != 6)
            {
                strError = "冒号后面的城市代码部分 '" + strCityCode + "' 应当为6字符";
                goto ERROR1;
            }
        }

        this.DetailForm.MarcEditor.Record.Fields.SetFirstSubfield("102", "a", strCountryCode);
        this.DetailForm.MarcEditor.Record.Fields.SetFirstSubfield("102", "b", strCityCode);
        return;

ERROR1:
        MessageBox.Show(this.DetailForm, strError);
    }
コード例 #18
0
        protected override async Task <Window> Load(ILoadingView loadingView)
        {
            var hostedGame = _game;

            try {
                Program.CurrentHostedGame = hostedGame;
                var password = string.Empty;
                if (Program.IsHost = _isHost)
                {
                    password = hostedGame.Password;
                }
                else
                {
                    if (hostedGame.HasPassword)
                    {
                        var dlg = new InputDlg("Password", "Please enter this games password", "");

                        password = dlg.GetString();
                    }
                }

                if (hostedGame.Source == HostedGameSource.Online)
                {
                    Program.CurrentOnlineGameName = hostedGame.Name;
                }

                loadingView.UpdateStatus("Loading game");
                var gm = GameManager.Get();

                var game = GameManager.Get().GetById(hostedGame.GameId);

                if (game == null)
                {
                    var msg = $"Game {hostedGame.GameName}({hostedGame.Id}) could not be found.";
                    throw new UserMessageException(UserMessageExceptionMode.Blocking, msg);
                }

                loadingView.UpdateStatus("Building engine");
                Program.GameEngine = new GameEngine(game, _username, _spectate, password);

                loadingView.UpdateStatus($"Connecting to {hostedGame.HostAddress}");
                await Task.Delay(100);

                Program.Client = await Connect(hostedGame.Host, hostedGame.Port);

                if (Program.Client == null)
                {
                    var msg = $"Unable to connect to {hostedGame.Name} at {hostedGame.HostAddress}";

                    throw new UserMessageException(UserMessageExceptionMode.Blocking, msg);
                }

                Window window = null;
                await Dispatcher.CurrentDispatcher.InvokeAsync(() => {
                    window = WindowManager.PlayWindow = new PlayWindow();

                    window.Closed += PlayWindow_Closed;

                    window.Show();
                }, DispatcherPriority.Background);

                return(window);
            } catch (Exception e) {
                var msg = $"Error joining game {hostedGame.Name}: {e.Message}";

                Log.Warn(msg, e);

                throw new UserMessageException(UserMessageExceptionMode.Blocking, msg, e);
            }
        }
コード例 #19
0
        /*
         * 微信公众号新图书馆dp2mserver账号
         * 命名:weixin_图书馆英文或中文简称(如weixin_cctb,weixin_tjsyzx)
         * 权限:getPatronInfo,searchBiblio,searchPatron,bindPatron,getBiblioInfo,getBiblioSummary,getItemInfo,circulation,getUserInfo,getRes
         * 义务:空
         * 单位:图书馆名称
         * 群组:gn:_lib_bb
         * gn:_lib_book
         * gn:_lib_homePage
         *
         * ===
         * 新图书馆安装dp2capo时创建的dp2mserver账号
         * 命名:capo_图书馆英文或中文简称(如capo_cctb,capo_tjsyzx)
         * 权限:空
         * 义务:getPatronInfo,searchBiblio,searchPatron,bindPatron,getBiblioInfo,getBiblioSummary,getItemInfo,circulation,getUserInfo,getRes
         * 单位:图书馆名称
         * 群组:gn:_patronNotify|-n
         * */

        async Task <bool> CreateCapoUser()
        {
            string strError = "";

            EnableControls(false);
            try
            {
                using (MessageConnectionCollection _channels = new MessageConnectionCollection())
                {
                    _channels.Login += _channels_LoginSupervisor;

                    MessageConnection connection = await _channels.GetConnectionAsyncLite(
                        this.textBox_url.Text,
                        "supervisor");

                    // 记忆用过的超级用户名和密码
                    this.ManagerUserName = connection.UserName;
                    this.ManagerPassword = connection.Password;

                    CancellationToken cancel_token = _cancel.Token;

                    string id = Guid.NewGuid().ToString();

                    string strDepartment = InputDlg.GetInput(
                        this,
                        "图书馆名",
                        "请指定图书馆名: ",
                        "",
                        this.Font);
                    if (strDepartment == null)
                    {
                        return(false);
                    }

                    bool bEanbleWebCall = false;
                    this.Invoke(new Action(() =>
                    {
                        DialogResult temp_result = MessageBox.Show(this,
                                                                   "是否允许 webCall (通过 dp2Router 访问 dp2library)?",
                                                                   "安装 dp2Capo",
                                                                   MessageBoxButtons.YesNo,
                                                                   MessageBoxIcon.Question,
                                                                   MessageBoxDefaultButton.Button2);
                        if (temp_result == System.Windows.Forms.DialogResult.Yes)
                        {
                            bEanbleWebCall = true;
                        }
                    }));

                    List <User> users = new List <User>();

                    User user = new User();
                    user.userName = this.textBox_userName.Text;
                    user.password = this.textBox_password.Text;
                    user.rights   = "";
                    // TODO: 看看除了 weixin_xxx 以外是否还有其他请求者需要许可
                    user.duty = ":weixinclient|" + MakeWeixinUserName(this.textBox_userName.Text) + ",getPatronInfo,searchBiblio,searchPatron,bindPatron,getBiblioInfo,getBiblioSummary,getItemInfo,circulation,getUserInfo,getRes,getSystemParameter";
                    if (bEanbleWebCall)
                    {
                        user.duty += ",webCall:router";
                    }
                    user.groups     = new string[] { "gn:_patronNotify|-n" };
                    user.department = strDepartment;
                    user.binding    = "ip:[current]";
                    user.comment    = "dp2Capo 专用账号";

                    users.Add(user);

                    MessageResult result = await connection.SetUsersAsyncLite("create",
                                                                              users,
                                                                              new TimeSpan(0, 1, 0),
                                                                              cancel_token);

                    if (result.Value == -1)
                    {
                        strError = "创建用户 '" + this.textBox_userName.Text + "' 时出错: " + result.ErrorInfo;
                        goto ERROR1;
                    }

                    return(true);
                }
            }
            catch (MessageException ex)
            {
                if (ex.ErrorCode == "Unauthorized")
                {
                    strError             = "以用户名 '" + ex.UserName + "' 登录时, 用户名或密码不正确";
                    this.ManagerUserName = "";
                    this.ManagerPassword = "";
                    goto ERROR1;
                }
                if (ex.ErrorCode == "HttpRequestException")
                {
                    strError = "dp2MServer URL 不正确,或 dp2MServer 尚未启动";
                    goto ERROR1;
                }
                strError = ex.Message;
                goto ERROR1;
            }
            catch (AggregateException ex)
            {
                strError = MessageConnection.GetExceptionText(ex);
                goto ERROR1;
            }
            catch (Exception ex)
            {
                strError = ex.Message;
                goto ERROR1;
            }
            finally
            {
                EnableControls(true);
            }
ERROR1:
            this.Invoke(new Action(() =>
            {
                MessageBox.Show(this, strError);
            }));
            return(false);
        }
コード例 #20
0
    // 维护260对照关系
    void Manage260()
    {
        string strError = "";
        string strISBN  = "";
        int    nRet     = 0;

        strISBN = this.DetailForm.MarcEditor.Record.Fields.GetFirstSubfield("020", "a").Trim();

        string strPublisherNumber = "";

        if (String.IsNullOrEmpty(strISBN) == false)
        {
            // 切割出 出版社 代码部分
            nRet = this.DetailForm.MainForm.GetPublisherNumber(strISBN,
                                                               out strPublisherNumber,
                                                               out strError);
            if (nRet == -1)
            {
                goto ERROR1;
            }
        }

        if (String.IsNullOrEmpty(strPublisherNumber) == true)
        {
            strPublisherNumber = "978-0-?";
        }

        strPublisherNumber = InputDlg.GetInput(
            this.DetailForm,
            "维护260对照表 -- 第1步",
            "请输入ISBN中出版社号码部分:",
            strPublisherNumber,
            this.DetailForm.MainForm.DefaultFont);
        if (strPublisherNumber == null)
        {
            return;     // 放弃整个操作
        }
        string strValue = "";

        nRet = this.DetailForm.GetPublisherInfo(strPublisherNumber,
                                                out strValue,
                                                out strError);
        if (nRet == -1)
        {
            goto ERROR1;
        }

        if (nRet == 0 || strValue == "")
        {
            // 获得现有的260字段 $a$b
            Field field_260 = this.DetailForm.MarcEditor.Record.Fields.GetOneField("260", 0);
            if (field_260 != null)
            {
                Subfield subfield_a = field_260.Subfields["a"];
                Subfield subfield_b = field_260.Subfields["b"];
                if (subfield_a != null && subfield_b != null &&
                    string.IsNullOrEmpty(subfield_a.Value) == false &&
                    string.IsNullOrEmpty(subfield_b.Value) == false)
                {
                    strValue = FilterDocument.TrimEndChar(subfield_a.Value.Trim()).Trim()
                               + ":"
                               + FilterDocument.TrimEndChar(subfield_b.Value.Trim()).Trim();
                }
            }

            if (string.IsNullOrEmpty(strValue) == true)
            {
                strValue = "出版地:出版社名";
            }
        }

        // 创建新条目
        strValue = InputDlg.GetInput(
            this.DetailForm,
            "维护260对照表 -- 第2步",
            "请输入ISBN出版社号码 '" + strPublisherNumber + "' 对应的 MARC21 260$a$c参数(格式 出版地:出版社名):",
            strValue,
            this.DetailForm.MainForm.DefaultFont);
        if (strValue == null)
        {
            return;     // 放弃整个操作
        }
        if (strValue == "")
        {
            goto DOSAVE;
        }

        // MessageBox.Show(this.DetailForm, strValue);

        // 把全角冒号替换为半角的形态
        strValue = strValue.Replace(":", ":");

        string strName = "";
        string strCity = "";

        nRet = strValue.IndexOf(":");
        if (nRet == -1)
        {
            strError = "输入的内容中缺少冒号";
            goto ERROR1;
            // strName = strValue;
        }
        else
        {
            strCity = strValue.Substring(0, nRet);
            strName = strValue.Substring(nRet + 1);
        }

        strValue = strCity + ":" + strName;

DOSAVE:
        nRet = this.DetailForm.SetPublisherInfo(strPublisherNumber,
                                                strValue,
                                                out strError);
        if (nRet == -1)
        {
            goto ERROR1;
        }
        return;

ERROR1:
        MessageBox.Show(this.DetailForm, strError);
    }
コード例 #21
0
        public GameEngine(Game def, string nickname, bool specator, string password = "", bool isLocal = false)
        {
            History = new JodsEngineHistory(def.Id);
            if (Program.IsHost)
            {
                History.Name = Program.CurrentOnlineGameName;
            }

            ReplayWriter = new ReplayWriter();

            LoadedCards          = new ObservableDeck();
            LoadedCards.Sections = new ObservableCollection <ObservableSection>();

            DeckStats = new DeckStatsViewModel();

            Spectator = specator;
            Program.GameMess.Clear();
            if (def.ScriptVersion.Equals(new Version(0, 0, 0, 0)))
            {
                Program.GameMess.Warning("This game doesn't have a Script Version specified. Please contact the game developer.\n\n\nYou can get in contact of the game developer here {0}", def.GameUrl);
                def.ScriptVersion = new Version(3, 1, 0, 0);
            }
            if (Versioned.ValidVersion(def.ScriptVersion) == false)
            {
                Program.GameMess.Warning(
                    "Can't find API v{0}. Loading the latest version.\n\nIf you have problems, get in contact of the developer of the game to get an update.\nYou can get in contact of them here {1}",
                    def.ScriptVersion, def.GameUrl);
                def.ScriptVersion = Versioned.LowestVersion;
            }
            else
            {
                var vmeta = Versioned.GetVersion(def.ScriptVersion);
                if (vmeta.DeleteDate <= DateTime.Now)
                {
                    Program.GameMess.Warning("This game requires an API version {0} which is no longer supported by OCTGN.\nYou can still play, however some aspects of the game may no longer function as expected, and it may be removed at any time.\nYou may want to contact the developer of this game and ask for an update.\n\nYou can find more information about this game at {1}."
                                             , def.ScriptVersion, def.GameUrl);
                }
            }
            //Program.ChatLog.ClearEvents();
            IsLocal       = isLocal;
            this.Password = password;
            Definition    = def;
            _table        = new Table(def.Table);
            if (def.Phases != null)
            {
                byte PhaseId = 1;
                _allPhases = def.Phases.Select(x => new Phase(PhaseId++, x)).ToList();
            }
            GlobalVariables = new Dictionary <string, string>();
            foreach (var varDef in def.GlobalVariables)
            {
                GlobalVariables.Add(varDef.Key, varDef.Value.Value);
            }
            ScriptApi     = Versioned.Get <ScriptApi>(Definition.ScriptVersion);
            this.Nickname = nickname;
            while (String.IsNullOrWhiteSpace(this.Nickname))
            {
                this.Nickname = Prefs.Nickname;
                if (string.IsNullOrWhiteSpace(this.Nickname))
                {
                    this.Nickname = Randomness.GrabRandomNounWord() + new Random().Next(30);
                }
                var retNick = this.Nickname;
                Application.Current.Dispatcher.Invoke(() =>
                {
                    var i   = new InputDlg("Choose a nickname", "Choose a nickname", Nickname);
                    retNick = i.GetString();
                });
                this.Nickname = retNick;
            }
            // Init fields
            CurrentUniqueId = 1;
            TurnNumber      = 0;
            if (Definition.GameBoards.ContainsKey(""))
            {
                GameBoard = Definition.GameBoards[""];
            }
            ActivePlayer = null;

            foreach (var size in Definition.CardSizes)
            {
                var front = ImageUtils.CreateFrozenBitmap(new Uri(size.Value.Front));
                var back  = ImageUtils.CreateFrozenBitmap(new Uri(size.Value.Back));
                _cardFrontsBacksCache.Add(size.Value.Name, new Tuple <BitmapImage, BitmapImage>(front, back));
            }
            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                // clear any existing players
                Play.Player.All.Clear();
                Player.Spectators.Clear();
                // Create the global player, if any
                if (Definition.GlobalPlayer != null)
                {
                    Play.Player.GlobalPlayer = new Play.Player(Definition, IsReplay);
                }
                // Create the local player
                Play.Player.LocalPlayer = new Player(Definition, this.Nickname, Program.UserId, 255, Crypto.ModExp(Prefs.PrivateKey), specator, true, IsReplay);
            }));
        }
コード例 #22
0
    // 加入出版地、出版者
    void AddPublisher()
    {
        string strError = "";
        string strISBN  = "";

        int nRet = 0;

        strISBN = this.DetailForm.MarcEditor.Record.Fields.GetFirstSubfield("010", "a");

        if (strISBN.Trim() == "")
        {
            strError = "记录中不存在010$a子字段,因此无法加出版社子字段";
            goto ERROR1;
        }

        // 切割出 出版社 代码部分
        string strPublisherNumber = "";

        nRet = this.DetailForm.MainForm.GetPublisherNumber(strISBN,
                                                           out strPublisherNumber,
                                                           out strError);
        if (nRet == -1)
        {
            goto ERROR1;
        }

        string strValue = "";

        nRet = this.DetailForm.GetPublisherInfo(strPublisherNumber,
                                                out strValue,
                                                out strError);
        if (nRet == -1)
        {
            goto ERROR1;
        }

        if (nRet == 0 || strValue == "")
        {
            // 创建新条目
            strValue = InputDlg.GetInput(
                this.DetailForm,
                null,
                "请输入ISBN出版社号 '" + strPublisherNumber + "' 对应的出版社名称(格式 出版地:出版社名):",
                "出版地:出版社名");
            if (strValue == null)
            {
                return; // 放弃整个操作
            }
            nRet = this.DetailForm.SetPublisherInfo(strPublisherNumber,
                                                    strValue,
                                                    out strError);
            if (nRet == -1)
            {
                goto ERROR1;
            }
        }

        // MessageBox.Show(this.DetailForm, strValue);

        // 把全角冒号替换为半角的形态
        strValue = strValue.Replace(":", ":");

        string strName = "";
        string strCity = "";

        nRet = strValue.IndexOf(":");
        if (nRet == -1)
        {
            strName = strValue;
        }
        else
        {
            strCity = strValue.Substring(0, nRet);
            strName = strValue.Substring(nRet + 1);
        }

        this.DetailForm.MarcEditor.Record.Fields.SetFirstSubfield("210", "a", strCity);
        this.DetailForm.MarcEditor.Record.Fields.SetFirstSubfield("210", "c", strName);
        return;

ERROR1:
        MessageBox.Show(this.DetailForm, strError);
    }
コード例 #23
0
    // 维护210对照关系
    // 2008/10/17 new add
    void Manage210()
    {
        string strError = "";
        string strISBN  = "";
        int    nRet     = 0;

        strISBN = this.DetailForm.MarcEditor.Record.Fields.GetFirstSubfield("010", "a").Trim();

        string strPublisherNumber = "";

        if (String.IsNullOrEmpty(strISBN) == false)
        {
            // 切割出 出版社 代码部分
            nRet = this.DetailForm.MainForm.GetPublisherNumber(strISBN,
                                                               out strPublisherNumber,
                                                               out strError);
            if (nRet == -1)
            {
                goto ERROR1;
            }
        }

        if (String.IsNullOrEmpty(strPublisherNumber) == true)
        {
            strPublisherNumber = "978-7-?";
        }

        strPublisherNumber = InputDlg.GetInput(
            this.DetailForm,
            "维护210对照表 -- 第1步",
            "请输入ISBN中出版社号码部分:",
            strPublisherNumber);
        if (strPublisherNumber == null)
        {
            return;     // 放弃整个操作
        }
        string strValue = "";

        nRet = this.DetailForm.GetPublisherInfo(strPublisherNumber,
                                                out strValue,
                                                out strError);
        if (nRet == -1)
        {
            goto ERROR1;
        }

        if (nRet == 0 || strValue == "")
        {
            strValue = "出版地:出版社名";
        }

        // 创建新条目
        strValue = InputDlg.GetInput(
            this.DetailForm,
            "维护210对照表 -- 第2步",
            "请输入ISBN出版社号码 '" + strPublisherNumber + "' 对应的UNIMARC 210$a$c参数(格式 出版地:出版社名):",
            strValue);
        if (strValue == null)
        {
            return;     // 放弃整个操作
        }
        if (strValue == "")
        {
            goto DOSAVE;
        }

        // MessageBox.Show(this.DetailForm, strValue);

        // 把全角冒号替换为半角的形态
        strValue = strValue.Replace(":", ":");

        string strName = "";
        string strCity = "";

        nRet = strValue.IndexOf(":");
        if (nRet == -1)
        {
            strError = "输入的内容中缺少冒号";
            goto ERROR1;
            // strName = strValue;
        }
        else
        {
            strCity = strValue.Substring(0, nRet);
            strName = strValue.Substring(nRet + 1);
        }

        strValue = strCity + ":" + strName;

DOSAVE:
        nRet = this.DetailForm.SetPublisherInfo(strPublisherNumber,
                                                strValue,
                                                out strError);
        if (nRet == -1)
        {
            goto ERROR1;
        }
        return;

ERROR1:
        MessageBox.Show(this.DetailForm, strError);
    }
コード例 #24
0
        async void MenuItem_modifyState_Click(object sender, EventArgs e)
        {
            string strError = "";

            string new_state = InputDlg.GetInput(this, "修改状态", "新状态值", "dontsync", this.Font);

            if (new_state == null)
            {
                return;
            }
            try
            {
                SetInfoRequest request = new SetInfoRequest();
                request.Operation = "setHistory";
                request.Entities  = new List <Entity>();

                foreach (ListViewItem item in this.listView_records.SelectedItems)
                {
                    RequestItem tag = item.Tag as RequestItem;
                    tag.State = new_state;
                    Record record = new Record {
                        Data = JsonConvert.SerializeObject(tag)
                    };
                    request.Entities.Add(new Entity
                    {
                        Action    = "change:state",
                        NewRecord = record
                    });
                }

                var connection = await ConnectionPool.GetConnectionAsync(this.comboBox_query_myAccount.Text);

                var result = await connection.SetInfoAsyncLite(this.comboBox_query_shelfAccount.Text,
                                                               request,
                                                               TimeSpan.FromSeconds(10),
                                                               default);

                if (result.Value == -1)
                {
                    strError = result.ErrorInfo;
                    goto ERROR1;
                }

                // 报错
                List <string> errors          = new List <string>();
                List <string> succeed_records = new List <string>();
                if (result.Entities != null)
                {
                    foreach (var entity in result.Entities)
                    {
                        if (string.IsNullOrEmpty(entity.ErrorInfo) == false)
                        {
                            errors.Add(entity.ErrorInfo);
                        }
                        else
                        {
                            succeed_records.Add(entity.NewRecord?.Data);
                        }
                    }
                }

                // 刷新成功修改了的行
                foreach (var record in succeed_records)
                {
                    if (string.IsNullOrEmpty(record))
                    {
                        continue;
                    }
                    var item = JsonConvert.DeserializeObject <RequestItem>(record);
                    RefreshLine(item.ID, item);
                }

                if (errors.Count > 0)
                {
                    MessageDialog.Show(this, $"出错:\r\n{StringUtil.MakePathList(errors, "\r\n")}");
                }
                return;
            }
            catch (Exception ex)
            {
                strError = ex.Message;
                goto ERROR1;
            }

ERROR1:
            MessageBox.Show(this, strError);
        }