Ejemplo n.º 1
0
        public static CharData Load(string name, UserConnection conn)
        {
            CharData retVal = null;

            if (!string.IsNullOrWhiteSpace(name))
            {
                string fileName = name.Trim();
                fileName = fileName.Substring(0, 1).ToUpperInvariant() + fileName.Substring(1).ToLowerInvariant();
                var path = Path.Combine(PLAYER_DIR, fileName);
                if (File.Exists(path))
                {
                    var contents = Encoding.ASCII.GetString(File.ReadAllBytes(path));
                    using (var sr = new StringReader(contents))
                    {
                        var done = false;
                        while (!done)
                        {
                            var letter = sr.ReadLetter();
                            if (letter == '*')
                            {
                                sr.ReadToEOL();
                                continue;
                            }

                            if (letter != '#')
                            {
                                throw new Exception("Load_char_obj: # not found.");
                            }

                            switch (sr.ReadWord().Trim())
                            {
                            case "PLAYERS":
                                retVal = LoadCharData(sr, conn);
                                break;

                            case "OBJECT":
                            case "END":
                                done = true;
                                break;

                            default:
                                throw new Exception("Load_char_obj: bad section.");
                            }
                        }
                    }
                }
            }
            if (retVal == null)
            {
                conn.Disconnect();
            }
            return(retVal);
        }