Esempio n. 1
0
        private void SetStartPositions(PositionData[] PosData)
        {
            string filePath = Path.Combine(Yad.Properties.Common.Settings.Default.Maps, _serverGameInfo.MapName);

            FileStream fs = null;

            try {
                fs = File.Open(filePath, FileMode.Open);
            }
            catch (FileNotFoundException ex) {
                MessageBox.Show("Map: " + ex.FileName + " not found!");
                InfoLog.WriteError("Map: " + ex.FileName + " not found");
                return;
            }
            BinaryFormatter bformatter = new BinaryFormatter();
            List <Point>    listPoint  = (List <Point>)bformatter.Deserialize(fs);

            fs.Close();
            int no = listPoint.Count;

            for (short i = 0; i < PosData.Length; ++i)
            {
                int   index = _rand.Next(listPoint.Count);
                Point pt    = listPoint[index];
                PosData[i].X = (short)pt.X;
                PosData[i].Y = (short)pt.Y;
                listPoint.Remove(pt);
            }
        }
Esempio n. 2
0
        private ResultType CreateGame(GameInfoMessage msg)
        {
            ResultType result = _server.GameManager.IsCreateGamePossible(msg.GameInfo);

            SendMessage(Utils.CreateResultMessage(ResponseType.CreateGame, result), msg.SenderId);
            if (ResultType.Successful == result)
            {
                _server.GameManager.CreateGameNoError(msg.GameInfo);
                result = _server.GameManager.IsJoinGamePossible(msg.GameInfo.Name, _server.GetPlayer(msg.SenderId));
                if (result == ResultType.Successful)
                {
                    _server.GameManager.JoinGame(msg.GameInfo.Name, _server.GetPlayer(msg.SenderId));
                }
                else
                {
                    InfoLog.WriteError("Join not possible after create!");
                }
            }
            return(result);

            /*ResultType resultType = _server.GameManager.CreateGame(msg.GameInfo);
             * if (resultType == ResultType.Successful) {
             *  ResultType joinResult = _server.GameManager.JoinGame(msg.GameInfo.Name, _server.GetPlayer(msg.SenderId));
             *  if (joinResult != ResultType.Successful) {
             *      InfoLog.WriteError("Join not possible after create!");
             *      return joinResult;
             *  }
             * }
             * return resultType;*/
        }
Esempio n. 3
0
 public void SendMessage(Message message)
 {
     if (tcpClient.Connected)
     {
         sender.AddItem(message);
     }
     else
     {
         InfoLog.WriteError("Not connected - cannot send a message", EPrefix.ClientInformation);
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Main processing method
        /// </summary>
        /// <param name="item">Message to process</param>
        public override void ProcessItem(Message item)
        {
            Player p = _gameServer.GetPlayer(item.SenderId);

            if (null == p)
            {
                InfoLog.WriteError("Processing message from not connected player!", EPrefix.GameMessageProccesing);
                return;
            }
            else
            {
                InfoLog.WriteInfo(string.Format(Resources.GameProcessStringFormat, item.Type.ToString(),
                                                _gameServer.Name, p.Login), EPrefix.GameMessageProccesing);
            }
            switch (item.Type)
            {
            case MessageType.TurnAsk:
                ProcessTurnAsk((MessageTurnAsk)item);
                break;

            case MessageType.Pause:
                ProcessPause(item.SenderId);
                break;

            case MessageType.Resume:
                ProcessResume(item.SenderId);
                break;

            case MessageType.Move:
            case MessageType.Destroy:
            case MessageType.CreateUnit:
            case MessageType.Build:
            case MessageType.Harvest:
            case MessageType.Attack:
            case MessageType.DeployMCV:
            case MessageType.BuildUnitMessage:
                ProcessGameMessage((GameMessage)item);
                break;

            case MessageType.EndGame:
                ProcessGameEnd((GameEndMessage)item);
                break;

            case MessageType.GameLeave:
                ProcessGameLeave(item);
                break;

            default:
                InfoLog.WriteInfo("Unknown message to process: " + item.Type, EPrefix.GameMessageProccesing);
                break;
            }
        }
Esempio n. 5
0
        public void LoadSounds()
        {
            if (!isInitialized)
            {
                return;
            }

            FMOD.RESULT result;

            this.Volume = InitializationSettings.Instance.SoundVolume;
            if (InitializationSettings.Instance.IsSoundMuted)
            {
                this.Mute();
            }

            FMOD.Sound sound = null;

            foreach (MiscSoundType miscType in Enum.GetValues(typeof(MiscSoundType)))
            {
                sound  = new FMOD.Sound();
                result = system.createSound(Settings.Default.SoundMisc + GetFileName(miscType), FMOD.MODE.HARDWARE, ref sound);
                if (!FMOD.ERROR.ERRCHECK(result))
                {
                    InfoLog.WriteError(GetFileName(miscType) + ": " + FMOD.ERROR.String(result), EPrefix.AudioEngine);
                }
                misc[(short)miscType] = sound;
            }

            foreach (short houseId in GlobalSettings.Instance.GetHouseIDs())
            {
                FMOD.Sound[] tableHouse = new FMOD.Sound[Enum.GetValues(typeof(HouseSoundType)).Length];

                foreach (HouseSoundType houseType in Enum.GetValues(typeof(HouseSoundType)))
                {
                    sound  = new FMOD.Sound();
                    result = system.createSound(Settings.Default.Sound + GlobalSettings.Instance.GetHouseName(houseId) + "/" + GetFileName(houseType), FMOD.MODE.HARDWARE, ref sound);
                    if (!FMOD.ERROR.ERRCHECK(result))
                    {
                        InfoLog.WriteError(GetFileName(houseType) + ": " + FMOD.ERROR.String(result), EPrefix.AudioEngine);
                    }
                    tableHouse[(short)houseType] = sound;
                }

                houses.Add(houseId, tableHouse);
            }

            InfoLog.WriteInfo("Finished loading sounds", EPrefix.AudioEngine);
        }
Esempio n. 6
0
        public void LoadMusic()
        {
            if (!isInitialized)
            {
                return;
            }

            FMOD.RESULT result;
            music   = new List <FMOD.Sound> [Enum.GetValues(typeof(MusicType)).Length];
            indices = new short[music.Length];

            this.Volume = InitializationSettings.Instance.MusicVolume;
            if (InitializationSettings.Instance.IsMusicMuted)
            {
                this.Mute();
            }

            for (int i = 0; i < music.Length; i++)
            {
                music[i]   = new List <FMOD.Sound>();
                indices[i] = 0;
            }

            DirectoryInfo directoryInfo = null;

            FMOD.Sound sound = null;

            directoryInfo = new DirectoryInfo(Settings.Default.MusicFight);
            foreach (FileInfo fileInfo in directoryInfo.GetFiles())
            {
                sound  = new FMOD.Sound();
                result = system.createSound(fileInfo.FullName, FMOD.MODE.SOFTWARE | FMOD.MODE.CREATESTREAM, ref sound);
                if (!FMOD.ERROR.ERRCHECK(result))
                {
                    InfoLog.WriteError(fileInfo.Name + ": " + FMOD.ERROR.String(result), EPrefix.AudioEngine);
                }
                music[(short)MusicType.Fight].Add(sound);
            }

            directoryInfo = new DirectoryInfo(Settings.Default.MusicLose);
            foreach (FileInfo fileInfo in directoryInfo.GetFiles())
            {
                sound  = new FMOD.Sound();
                result = system.createSound(fileInfo.FullName, FMOD.MODE.SOFTWARE | FMOD.MODE.CREATESTREAM, ref sound);
                if (!FMOD.ERROR.ERRCHECK(result))
                {
                    InfoLog.WriteError(fileInfo.Name + ": " + FMOD.ERROR.String(result), EPrefix.AudioEngine);
                }
                music[(short)MusicType.Lose].Add(sound);
            }

            directoryInfo = new DirectoryInfo(Settings.Default.MusicPeace);
            foreach (FileInfo fileInfo in directoryInfo.GetFiles())
            {
                sound  = new FMOD.Sound();
                result = system.createSound(fileInfo.FullName, FMOD.MODE.SOFTWARE | FMOD.MODE.CREATESTREAM, ref sound);
                if (!FMOD.ERROR.ERRCHECK(result))
                {
                    InfoLog.WriteError(fileInfo.Name + ": " + FMOD.ERROR.String(result), EPrefix.AudioEngine);
                }
                music[(short)MusicType.Peace].Add(sound);
            }

            directoryInfo = new DirectoryInfo(Settings.Default.MusicWin);
            foreach (FileInfo fileInfo in directoryInfo.GetFiles())
            {
                sound  = new FMOD.Sound();
                result = system.createSound(fileInfo.FullName, FMOD.MODE.SOFTWARE | FMOD.MODE.CREATESTREAM, ref sound);
                if (!FMOD.ERROR.ERRCHECK(result))
                {
                    InfoLog.WriteError(fileInfo.Name + ": " + FMOD.ERROR.String(result), EPrefix.AudioEngine);
                }
                music[(short)MusicType.Win].Add(sound);
            }

            InfoLog.WriteInfo("Finished loading music", EPrefix.AudioEngine);
        }