Esempio n. 1
0
        public ProfileScreen(GameScreen parentScreen)
        {
            keyboardInput        = new StringBuilder();
            profileStringBuilder = new KeyboardStringBuilder();

            ParentScreen = parentScreen;
            ParentScreen.currentScreenState = ScreenState.Hidden;

            profileFiles = FileGrabber.findLocalProfiles();
            createProfilesMenuEntries(profileFiles);
            menuEntries.Add(new MenuEntry("New"));
            menuEntries.Add(new MenuEntry("Cancel"));

            if (profileEntries.Count > 0)
            {
                onProfiles               = true;
                selectedProfileEntry     = 0;
                profileEntries[0].Active = true;
            }
            else
            {
                onMenu                = true;
                selectedMenuEntry     = 0;
                menuEntries[0].Active = true;
            }
        }
Esempio n. 2
0
        private string _generateSource(SourceType ext, List <string> pattern, bool inline)
        {
            Dictionary <string, FileType> attached = this._getAttached(ext);
            List <string> stringList = new List <string>();
            string        str1       = this.Codebase != (string)null ? this.Codebase + "/" : "";

            foreach (KeyValuePair <string, FileType> keyValuePair in attached)
            {
                string str2 = keyValuePair.Key;
                if (!string.IsNullOrEmpty(this.Version) && !str2.Contains("google.com"))
                {
                    str2 = str2 + (str2.IndexOf('?') < 0 ? "?v=" : "&v=") + this.Version;
                }
                if (!inline)
                {
                    stringList.Add(pattern[0] + (keyValuePair.Value == FileType.Local ? str1 : "") + str2 + pattern[1]);
                }
                else
                {
                    FileGrabber fileGrabber = new FileGrabber();
                    string      str3        = (keyValuePair.Value == FileType.Local ? str1 : "") + str2;
                    string      str4        = !Regex.IsMatch(str3, "http(s)?://([\\w+?\\.\\w+])+([a-zA-Z0-9\\~\\!\\@\\#\\$\\%\\^\\&amp;\\*\\(\\)_\\-\\=\\+\\\\\\/\\?\\.\\:\\;\\'\\,]*)?") ? fileGrabber.GetLocalFile(str3) : fileGrabber.GetRemoteFile(str3);
                    stringList.Add(pattern[0] + str4 + pattern[1]);
                }
            }
            return(string.Join("\n", stringList.ToArray()));
        }
 public void SaveAllPlayerData(bool isLocalGame)
 {
     foreach (String username in PlayerEntities.Keys.ToList())
     {
         EntityFactory.DumpEntityIntoSaveFile(PlayerEntities[username], PlayerSaves[username]);
         FileGrabber.SavePlayer(isLocalGame, PlayerSaves[username]);
     }
 }
 public void HandleDisconnect(bool isLocalGame, string username)
 {
     if (PlayerEntities.ContainsKey(username))
     {
         EntityFactory.DumpEntityIntoSaveFile(PlayerEntities[username], PlayerSaves[username]);
         FileGrabber.SavePlayer(isLocalGame, PlayerSaves[username]);
         PlayerEntities.Remove(username);
         PlayerSaves.Remove(username);
         RUIDUsernames.Remove(username);
     }
 }
Esempio n. 5
0
        public override void HandleInput(InputState input)
        {
            if (input.IsNewKeyPress(Keys.Up))
            {
                if (onProfiles)
                {
                    selectedProfileEntry--;

                    if (selectedProfileEntry < 0)
                    {
                        selectedProfileEntry = -1;
                        selectedMenuEntry    = menuEntries.Count - 1;
                        onProfiles           = false;
                        onMenu = true;
                    }
                }
                else if (onMenu)
                {
                    selectedMenuEntry--;

                    if (selectedMenuEntry < 0)
                    {
                        if (profileEntries.Count > 0)
                        {
                            selectedMenuEntry    = -1;
                            selectedProfileEntry = profileEntries.Count - 1;
                            onProfiles           = true;
                            onMenu = false;
                        }
                        else
                        {
                            selectedMenuEntry = menuEntries.Count - 1;
                        }
                    }
                }
            }
            if (input.IsNewKeyPress(Keys.Down))
            {
                if (onProfiles)
                {
                    selectedProfileEntry++;

                    if (selectedProfileEntry >= profileEntries.Count)
                    {
                        selectedProfileEntry = -1;
                        selectedMenuEntry    = 0;
                        onProfiles           = false;
                        onMenu = true;
                    }
                }
                else if (onMenu)
                {
                    selectedMenuEntry++;

                    if (selectedMenuEntry >= menuEntries.Count)
                    {
                        if (profileEntries.Count > 0)
                        {
                            selectedMenuEntry    = -1;
                            selectedProfileEntry = 0;
                            onProfiles           = true;
                            onMenu = false;
                        }
                        else
                        {
                            selectedMenuEntry = 0;
                        }
                    }
                }
            }
            if (input.IsNewKeyPress(Keys.Enter))
            {
                if (onMenu)
                {
                    switch (selectedMenuEntry)
                    {
                    case (int)ProfileEntry.New:
                        if (newProfileActive)
                        {
                            // done typing (save it)
                            string newProfileName = keyboardInput.ToString();
                            if (profileFiles != null && profileFiles.Length > 0)
                            {
                                if (doesProfileExist(newProfileName))
                                {
                                    screenManager.AddScreen(new PopUpWarningScreen(this, GameConstants.DuplicateProfile));
                                }
                                else
                                {
                                    profileFiles.Concat(new string[] { newProfileName });
                                    FileGrabber.createNewProfile(newProfileName);
                                    profileEntries.Add(new MenuEntry(newProfileName));
                                }
                            }
                            else
                            {
                                profileFiles = new string[] { newProfileName };
                                FileGrabber.createNewProfile(newProfileName);
                                profileEntries.Add(new MenuEntry(newProfileName));
                            }
                            keyboardInput.Clear();
                            newProfileActive = false;
                        }
                        else if (!newProfileActive)
                        {
                            // start taking keystrokes
                            newProfileActive = true;
                        }
                        break;

                    case (int)ProfileEntry.Cancel:
                        screenManager.RemoveScreen(this);
                        ParentScreen.currentScreenState = ScreenState.Active;
                        break;
                    }
                }
                else if (onProfiles)
                {
                    NetworkManager.Instance.SingleplayerStart();

                    // time to send off profile name and "local" keyword
                    UsernameKeywordComboPacket packet = new UsernameKeywordComboPacket();
                    packet.username = Path.GetFileNameWithoutExtension(profileFiles[selectedProfileEntry]);
                    packet.keyword  = "local";
                    Thread.Sleep(1000); // <--- need this else packet kicks off before server thread is ready
                    NetworkManager.Instance.SendReliableData(packet);

                    // stupid thing so we can stay at the same handshake process as multiplayer
                    while (NetworkManager.Instance.Verified.Equals(""))
                    {
                    }

                    screenManager.AddScreen(new MainGameScreen(packet.username));
                    screenManager.RemoveScreen(this);
                }
            }
            if (input.IsNewKeyPress(Keys.Escape))
            {
                if (newProfileActive)
                {
                    keyboardInput.Clear();
                    newProfileActive = false;
                }
                screenManager.RemoveScreen(this);
                ParentScreen.currentScreenState = ScreenState.Active;
            }
        }
Esempio n. 6
0
        private void HandlePacket(NetIncomingMessage msg)
        {
            PacketType type = (PacketType)msg.ReadByte();

            switch (type)
            {
            case PacketType.UsernameKeywordCombo:
                UsernameKeywordComboPacket unkwPacket = new UsernameKeywordComboPacket();
                unkwPacket.Unpack(msg);
                if (gameManager.PlayerSaves.ContainsKey(unkwPacket.username))
                {
                    LoginVerificationPacket packet = new LoginVerificationPacket();
                    packet.message = "You are already logged in.";
                    ServerConsoleMessage(unkwPacket.username + " login error: Already logged in.");
                    SendUnconnectedMessage(packet, msg.SenderEndpoint);
                    //server.Connections.Remove(server.GetConnection(msg.SenderEndpoint));  // try
                }
                else
                {
                    PlayerSave save = FileGrabber.getPlayerSave(isLocalGame, unkwPacket.username, unkwPacket.keyword);
                    if (!unkwPacket.keyword.Equals(save.Keyword))
                    {
                        LoginVerificationPacket packet = new LoginVerificationPacket();
                        packet.message = "Keyword does not match.";
                        ServerConsoleMessage(unkwPacket.username + " login error: Bad keyword.");
                        SendUnconnectedMessage(packet, msg.SenderEndpoint);
                        //server.Connections.Remove(server.GetConnection(msg.SenderEndpoint));  // try
                    }
                    else
                    {
                        LoginVerificationPacket packet = new LoginVerificationPacket();
                        packet.message = "verified";
                        gameManager.PlayerSaves.Add(unkwPacket.username, save);
                        gameManager.createPlayerEntityFromSave(unkwPacket.username);
                        gameManager.RUIDUsernames.Add(unkwPacket.username, msg.SenderConnection.RemoteUniqueIdentifier);
                        SendUnconnectedMessage(packet, msg.SenderEndpoint);
                        ServerConsoleMessage(unkwPacket.username + " has logged into the game.");
                        if (!isLocalGame)
                        {
                            ChatMessageQueue.Enqueue(new ChatMessage("SERVER", unkwPacket.username + " has connected."));
                        }
                    }
                }
                break;

            case PacketType.ChatMessage:
                ChatMessagePacket chatPacket = new ChatMessagePacket();
                chatPacket.Unpack(msg);
                string username = gameManager.RUIDUsernames.GetValue(msg.SenderConnection.RemoteUniqueIdentifier);
                if (!username.Equals(""))
                {
                    ChatMessage cmsg = new ChatMessage(username, chatPacket.message);
                    ChatMessageQueue.Enqueue(cmsg);
                    ServerConsoleMessage(cmsg.getChatString());
                }
                break;

            case PacketType.InputsPacket:
                InputsPacket inputsPacket = new InputsPacket();
                inputsPacket.Unpack(msg);
                string un = gameManager.RUIDUsernames.GetValue(msg.SenderConnection.RemoteUniqueIdentifier);
                if (!un.Equals(""))
                {
                    gameManager.HandlePlayerMoving(un, inputsPacket);
                }
                break;
            }
        }
Esempio n. 7
0
 private void CreateNewProfile(string newProfileName)
 {
     ProfileFiles = new string[] { newProfileName };
     FileGrabber.createNewProfile(newProfileName);
     ProfileEntries.Add(new MenuEntry(newProfileName));
 }