예제 #1
0
 private bool checkMapExist(mapInfo map)
 {
     Directory.CreateDirectory("maps");
     string fpath=Path.Combine("maps",map.name);
     if (!File.Exists(fpath)) return false;
     var fstream = File.OpenRead(fpath);
     var md5 = System.Security.Cryptography.MD5.Create();
     var localHash = md5.ComputeHash(fstream);
     fstream.Dispose();
     if (localHash.Length != map.hashCode.Length) return false;
     for (int i = 0; i < localHash.Length; i++) {
         if (localHash[i] != map.hashCode[i]) {
             return false;
         }
     }
     return true;
 }
예제 #2
0
        void frmServer_Load(object sender, EventArgs e)
        {
            //читаем карты - просто смотрим все файлы в папке
            Directory.CreateDirectory("maps");
            var files=Directory.GetFiles("maps");
            foreach (var file in files) {
                try {

                    Image im = Image.FromFile(file);
                    mapInfo map = new mapInfo();
                    clsGame game=new clsGame();
                    MD5 md5 = MD5.Create();
                    var fstream=File.OpenRead(file);
                    map.hashCode = md5.ComputeHash(fstream);
                    map.width = (ushort)im.Width;
                    map.height = (ushort)im.Height;
                    map.name = Path.GetFileName(file);

                    fstream.Close();
                    fstream.Dispose();
                    im.Dispose();
                    lstGames.Items.Add(map.name);
                    game.Map = map;
                    games.Add(map.name, game);
                }catch(Exception ex){
                }
            }
            connectWaitThread = new Thread(connectWaitProcess);
            threads.Add(connectWaitThread);
            connectWaitThread.Start();
        }