Exemple #1
0
        public int SyncTile(Util.DBHelper db)
        {
            // 타일의 배열이 존재하는 문서를 얻어옴.
            var tileArrayDoc = db.GetDocument("Tiles", "Tiles");

            // 문서가 존재하지 않으면 만든 뒤 새 타일정보로 채우고
            // 존재한다면 DB의 타일정보를 받아와 적용시킨다.
            if (tileArrayDoc == null)
            {
                // 타일 배열을 만들고 타일의 정보를 등록.
                var tileArr = new BsonArray(m_tileMap.Length);
                foreach (var tile in m_tileMap)
                {
                    tileArr.Add(tile.ToBsonDocument());
                }

                // 타일목록 문서를 생성.
                tileArrayDoc = db.CreateDocument("Tiles", "Tiles",
                    new BsonDocument
                    {
                        { "List", tileArr }
                    });
            }
            else
            {
                // 문서에서 타일배열을 얻어옴.
                var tileArray = tileArrayDoc["List"].AsBsonArray;
                
                // DB타일의 정보를 인덱스에 해당하는 타일에 설정.
                for (int index = 0;
                    index < tileArray.Count && index < m_tileMap.Length;
                    ++index)
                {
                    SyncTileAt(db, tileArray, index);
                }
            }


            return 0;
        }
Exemple #2
0
        public int SyncServerMessage(Util.DBHelper db)
        {
            var shutdownDoc = db.GetDocument("Server", "Shutdown");
            if (shutdownDoc == null)
            {
                shutdownDoc = db.CreateDocument("Server", "Shutdown",
                    new BsonDocument()
                    {
                        { "Flag", false },
                        { "Message", "" }
                    });
            }
            else
            {
                var flag = shutdownDoc["Flag"].AsBoolean;
                var msg = shutdownDoc["Message"].AsString;

                this.ShutdownFlag = flag;
                this.ShutdownMessage = msg;


                // 메세지가 있고 이전 메세지와 다르면 이벤트 발생
                if (msg.Length > 0 && m_prevShutMsg != msg && this.WhenShutdownMessageChanged != null)
                    this.WhenShutdownMessageChanged(msg, flag);


                m_prevShutMsg = msg;
            }


            return 0;
        }
Exemple #3
0
        public int SyncMapSize(Util.DBHelper db)
        {
            // 맵 크기 정보를 얻어옴.
            var mapSizeDoc = db.GetDocument("MapInfo", "MapSize");
            if (mapSizeDoc == null)
            {
                mapSizeDoc = db.CreateDocument("MapInfo", "MapSize",
                    new BsonDocument
                    {
                        { "Width", 64 },
                        { "Height", 64 }
                    });
            }

            int width = mapSizeDoc["Width"].AsInt32;
            int height = mapSizeDoc["Height"].AsInt32;

            // 타일맵이 없거나 DB의 맵 크기와 다르면 새로 생성한다.
            if (m_tileMap == null
                ||
                width != this.Width || height != this.Height)
            {
                m_tileMap = new GameTile[width, height];

                for (int w = 0; w < width; ++w)
                {
                    for (int h = 0; h < height; ++h)
                    {
                        m_tileMap[w, h] = new GameTile();
                        m_tileMap[w, h].Index = w * height + h;
                        m_tileMap[w, h].IsLastVersion = true;
                    }
                }
            }


            return 0;
        }