示例#1
0
        private void Launch()
        {
            ReplayInfo replayInfo = (ReplayInfo)m_replaysListBox.SelectedItem;

            GameServer.SetReplay(m_gSettings.ClientId, replayInfo.Id, error4 =>
            {
                m_progress.IsVisible = false;
                if (GameServer.HasError(error4))
                {
                    OutputError(error4);
                    return;
                }

                GameServer.Launch(m_gSettings.ClientId, (error, serverUrl) =>
                {
                    if (GameServer.HasError(error))
                    {
                        m_progress.IsVisible = false;
                        OutputError(error);
                        return;
                    }

                    m_gSettings.MatchServerUrl = serverUrl;

                    m_navigation.ClearHistory();
                    m_navigation.Navigate("Game");
                });
            });
        }
示例#2
0
        private void OnItemDataBinding(object sender, ItemDataBindingArgs e)
        {
            ReplayInfo replayInfo = (ReplayInfo)e.Item;

            Text text = e.ItemPresenter.GetComponent <Text>();

            text.text = string.Format("{0} [{1}]", replayInfo.Name, new System.DateTime(replayInfo.DateTime).ToLocalTime().ToString());
        }
示例#3
0
        private void OnCreateButtonClick()
        {
            m_progress.IsVisible = true;
            DetroyRoomIfCreated(() =>
            {
                ReplayInfo replayInfo = (ReplayInfo)m_replaysListBox.SelectedItem;

                GameServer.CreateRoom(m_gSettings.ClientId, replayInfo.MapId, GameMode.Replay, (error, room) =>
                {
                    if (GameServer.HasError(error))
                    {
                        m_progress.IsVisible = false;
                        OutputError(error);
                        return;
                    }

                    m_room = room;

                    BotType[] botTypes = new BotType[replayInfo.PlayerNames.Length];
                    for (int i = 0; i < botTypes.Length; ++i)
                    {
                        botTypes[i] = BotType.Replay;
                    }

                    GameServer.CreateBots(m_gSettings.ClientId, replayInfo.PlayerNames, botTypes, (error2, guids2, room2) =>
                    {
                        if (GameServer.HasError(error2))
                        {
                            m_progress.IsVisible = false;
                            OutputError(error2);
                            return;
                        }

                        m_room = room2;
                        Launch();
                    });
                });
            },
                                error =>
            {
                m_progress.IsVisible = false;
                OutputError(error);
            });
        }
示例#4
0
        public void SaveReplay(Guid clientId, string name, ServerEventHandler callback)
        {
            MatchServer.GetReplay(clientId, (error, replayData, room) =>
            {
                if (HasError(error))
                {
                    callback(error);
                    return;
                }

                ReplayInfo replayInfo  = new ReplayInfo();
                replayInfo.DateTime    = DateTime.UtcNow.Ticks;
                replayInfo.Name        = name;
                replayInfo.Id          = replayData.Id = Guid.NewGuid();
                replayInfo.MapId       = Room.MapInfo.Id;
                replayInfo.PlayerNames = Room.Players.Skip(1).Select(r => m_players[r].Name).ToArray();

                error.Code = StatusCode.OK;

                string dataPath = m_persistentDataPath + "/Replays/";
                if (!Directory.Exists(dataPath))
                {
                    Directory.CreateDirectory(dataPath);
                }

                byte[] replayInfoBytes = m_serializer.Serialize(replayInfo);

                File.WriteAllBytes(dataPath + replayInfo.Id + ".info", replayInfoBytes);

                byte[] replayDataBytes = m_serializer.Serialize(replayData);

                File.WriteAllBytes(dataPath + replayData.Id + ".data", replayDataBytes);

                if (m_lag == 0)
                {
                    callback(error);
                }
                else
                {
                    Job.Submit(() => { Thread.Sleep(m_lag); return(null); }, result => callback(error));
                }
            });
        }
示例#5
0
        public void GetReplays(Guid clientId, ServerEventHandler <ReplayInfo[]> callback)
        {
            ReplayInfo[] replaysInfo = null;
            Error        error       = new Error();

            error.Code = StatusCode.OK;

            try
            {
                string dataPath = m_persistentDataPath + "/Replays/";

                if (Directory.Exists(dataPath))
                {
                    string[] filePath = Directory.GetFiles(dataPath, "*.info", SearchOption.TopDirectoryOnly);
                    replaysInfo = new ReplayInfo[filePath.Length];
                    for (int i = 0; i < filePath.Length; ++i)
                    {
                        byte[] replayInfoBytes = File.ReadAllBytes(filePath[i]);
                        replaysInfo[i] = m_serializer.Deserialize <ReplayInfo>(replayInfoBytes);
                    }
                }
                else
                {
                    replaysInfo = new ReplayInfo[0];
                }
            }
            catch (Exception e)
            {
                error.Code    = StatusCode.UnhandledException;
                error.Message = e.Message;
            }

            if (m_lag == 0)
            {
                callback(error, replaysInfo);
            }
            else
            {
                Job.Submit(() => { Thread.Sleep(m_lag); return(null); }, result => callback(error, replaysInfo));
            }
        }
        public void GetReplays(Guid clientId, ServerEventHandler <ReplayInfo[]> callback)
        {
            RemoteCall rpc = new RemoteCall(
                RemoteCall.Proc.GetReplays,
                clientId);

            Call(rpc, (error, result) =>
            {
                ByteArray[] replayInfoBin = result.Get <ByteArray[]>(0);
                ReplayInfo[] replayInfo   = new ReplayInfo[0];
                if (replayInfo != null && !HasError(error))
                {
                    replayInfo = new ReplayInfo[replayInfoBin.Length];
                    for (int i = 0; i < replayInfo.Length; ++i)
                    {
                        replayInfo[i] = m_serializer.Deserialize <ReplayInfo>(replayInfoBin[i]);
                    }
                }
                callback(error, replayInfo);
            });
        }