public JoinGame(MainWindow mainWindow, ProtocolHandler ph) { InitializeComponent(); this.ph = ph; MainWindow = mainWindow; gameIDTextbox.Text = ""; }
public Login(MainWindow mainWindow, ProtocolHandler ph) { InitializeComponent(); this.ph = ph; MainWindow = mainWindow; }
/// <summary> /// Creates a new GameBoard page. /// </summary> /// <param name="ph">The ProtocolHandler used to stage connections.</param> /// <param name="thisPlayer">The player using this client.</param> /// <param name="opponent">The opponent of the player using this client.</param> public GameBoard(MainWindow mainWindow, ProtocolHandler ph, Player thisPlayer, Player opponent, bool thisPlayersTurn, int GameID) { InitializeComponent(); this.GameID = GameID; MainWindow = mainWindow; this.ph = ph; SocketArgs = ph.GetMoveArgs(); SocketArgs.Completed += new EventHandler<SocketAsyncEventArgs>(ReceiveOpponentsMove); this.thisPlayersTurn = thisPlayersTurn; Board = new List<GameBoardSpot>() { new GameBoardSpot(spot1Label), new GameBoardSpot(spot2Label), new GameBoardSpot(spot3Label), new GameBoardSpot(spot4Label), new GameBoardSpot(spot5Label), new GameBoardSpot(spot6Label), new GameBoardSpot(spot7Label), new GameBoardSpot(spot8Label), new GameBoardSpot(spot9Label) }; Player = thisPlayer; Opponent = opponent; playerLabel.Content = String.Format("{0}({1})", Player.Nickname, Player.Symbol); opponentLabel.Content = String.Format("{0}({1})", Opponent.Nickname, Opponent.Symbol); if (!thisPlayersTurn) { playerLabel.FontWeight = FontWeights.Normal; opponentLabel.FontWeight = FontWeights.Bold; statusLabel.Content = "Waiting on opponent..."; ph.GetMove(SocketArgs); } }
public CreateGame(MainWindow mainWindow, ProtocolHandler ph) { InitializeComponent(); this.ph = ph; MainWindow = mainWindow; ///Waits for someone to join the game. ///Also animates the waiting label. _waitingAction = delegate () { try { int numberOfPeriods = 1; while (_waitingForConnection && (bool)this.Dispatcher.Invoke((Func<bool>)(() => MainWindow.ProtocolHandler.Client.Available == 0))) { this.Dispatcher.Invoke((Action)(() => waitingLabel.Content = String.Format("Waiting on opponent{0}", new string('.', numberOfPeriods)) )); if (numberOfPeriods <= 6) numberOfPeriods++; else numberOfPeriods = 1; System.Threading.Thread.Sleep(350); } if (_waitingForConnection) { Player opponent = (Player)this.Dispatcher.Invoke((Func<Player>)(() => ph.GetOpponent())); this.Dispatcher.Invoke((Action)(() => MainWindow.GenerateNewGame(opponent, true, gameID))); } } catch (NullReferenceException) { } }; _waitingOperation = new Thread(_waitingAction.Invoke); }
public DelegationsCommit(ProtocolHandler protocol) : base(protocol) { }
BootstrapCommit(ProtocolHandler protocol) : base(protocol) { }
public TransactionsCommit(ProtocolHandler protocol) : base(protocol) { }
public Validator(ProtocolHandler protocol) : base(protocol) { }
public RevealsCommit(ProtocolHandler protocol) : base(protocol) { }
public ProtoActivator(ProtocolHandler protocol) : base(protocol) { }
/// <summary> /// Start a new Client /// </summary> private static void InitializeClient() { SessionToken session = new SessionToken(); ProtocolHandler.LoginResult result = ProtocolHandler.LoginResult.LoginRequired; if (Settings.Password == "-") { ConsoleIO.WriteLineFormatted("§8You chose to run in offline mode."); result = ProtocolHandler.LoginResult.Success; session.PlayerID = "0"; session.PlayerName = Settings.Login; } else { // Validate cached session or login new session. if (Settings.SessionCaching != CacheType.None && SessionCache.Contains(Settings.Login.ToLower())) { session = SessionCache.Get(Settings.Login.ToLower()); result = ProtocolHandler.GetTokenValidation(session); if (result != ProtocolHandler.LoginResult.Success) { ConsoleIO.WriteLineFormatted("§8Cached session is invalid or expired."); if (Settings.Password == "") { RequestPassword(); } } else { ConsoleIO.WriteLineFormatted("§8Cached session is still valid for " + session.PlayerName + '.'); } } if (result != ProtocolHandler.LoginResult.Success) { Console.WriteLine("Connecting to Minecraft.net..."); result = ProtocolHandler.GetLogin(Settings.Login, Settings.Password, out session); if (result == ProtocolHandler.LoginResult.Success && Settings.SessionCaching != CacheType.None) { SessionCache.Store(Settings.Login.ToLower(), session); } } } if (result == ProtocolHandler.LoginResult.Success) { Settings.Username = session.PlayerName; if (Settings.ConsoleTitle != "") { Console.Title = Settings.ExpandVars(Settings.ConsoleTitle); } if (Settings.playerHeadAsIcon) { ConsoleIcon.setPlayerIconAsync(Settings.Username); } if (Settings.DebugMessages) { Console.WriteLine("Success. (session ID: " + session.ID + ')'); } //ProtocolHandler.RealmsListWorlds(Settings.Username, PlayerID, sessionID); //TODO REMOVE if (Settings.ServerIP == "") { Console.Write("Server IP : "); Settings.SetServerIP(Console.ReadLine()); } //Get server version int protocolversion = 0; ForgeInfo forgeInfo = null; if (Settings.ServerVersion != "" && Settings.ServerVersion.ToLower() != "auto") { protocolversion = Protocol.ProtocolHandler.MCVer2ProtocolVersion(Settings.ServerVersion); if (protocolversion != 0) { ConsoleIO.WriteLineFormatted("§8Using Minecraft version " + Settings.ServerVersion + " (protocol v" + protocolversion + ')'); } else { ConsoleIO.WriteLineFormatted("§8Unknown or not supported MC version '" + Settings.ServerVersion + "'.\nSwitching to autodetection mode."); } if (useMcVersionOnce) { useMcVersionOnce = false; Settings.ServerVersion = ""; } } if (protocolversion == 0) { Console.WriteLine("Retrieving Server Info..."); if (!ProtocolHandler.GetServerInfo(Settings.ServerIP, Settings.ServerPort, ref protocolversion, ref forgeInfo)) { HandleFailure("Failed to ping this IP.", true, ChatBots.AutoRelog.DisconnectReason.ConnectionLost); return; } } if (protocolversion != 0) { try { //Start the main TCP client if (Settings.SingleCommand != "") { Client = new McTcpClient(session.PlayerName, session.PlayerID, session.ID, Settings.ServerIP, Settings.ServerPort, protocolversion, forgeInfo, Settings.SingleCommand); } else { Client = new McTcpClient(session.PlayerName, session.PlayerID, session.ID, protocolversion, forgeInfo, Settings.ServerIP, Settings.ServerPort); } //Update console title if (Settings.ConsoleTitle != "") { Console.Title = Settings.ExpandVars(Settings.ConsoleTitle); } } catch (NotSupportedException) { HandleFailure("Cannot connect to the server : This version is not supported !", true); } } else { HandleFailure("Failed to determine server version.", true); } } else { Console.ForegroundColor = ConsoleColor.Gray; string failureMessage = "Minecraft Login failed : "; switch (result) { case ProtocolHandler.LoginResult.AccountMigrated: failureMessage += "Account migrated, use e-mail as username."; break; case ProtocolHandler.LoginResult.ServiceUnavailable: failureMessage += "Login servers are unavailable. Please try again later."; break; case ProtocolHandler.LoginResult.WrongPassword: failureMessage += "Incorrect password."; break; case ProtocolHandler.LoginResult.NotPremium: failureMessage += "User not premium."; break; case ProtocolHandler.LoginResult.OtherError: failureMessage += "Network error."; break; case ProtocolHandler.LoginResult.SSLError: failureMessage += "SSL Error."; break; default: failureMessage += "Unknown Error."; break; } if (result == ProtocolHandler.LoginResult.SSLError && isUsingMono) { ConsoleIO.WriteLineFormatted("§8It appears that you are using Mono to run this program." + '\n' + "The first time, you have to import HTTPS certificates using:" + '\n' + "mozroots --import --ask-remove"); return; } HandleFailure(failureMessage, false, ChatBot.DisconnectReason.LoginRejected); } }
BakerCycleCommit(ProtocolHandler protocol) : base(protocol) { }
public ActivationsCommit(ProtocolHandler protocol) : base(protocol) { }
public SnapshotBalanceCommit(ProtocolHandler protocol) : base(protocol) { }
public SoftwareCommit(ProtocolHandler protocol) : base(protocol) { }
public FreezerCommit(ProtocolHandler protocol) : base(protocol) { }
DeactivationCommit(ProtocolHandler protocol) : base(protocol) { }
public ProposalsCommit(ProtocolHandler protocol) : base(protocol) { }
BallotsCommit(ProtocolHandler protocol) : base(protocol) { }
public BigMapCommit(ProtocolHandler protocol) : base(protocol) { }
public Diagnostics(ProtocolHandler handler) : base(handler) { }
public StateCommit(ProtocolHandler protocol) : base(protocol) { }
public DelegatorCycleCommit(ProtocolHandler protocol) : base(protocol) { }
RevelationPenaltyCommit(ProtocolHandler protocol) : base(protocol) { }
public OriginationsCommit(ProtocolHandler protocol) : base(protocol) { }
NonceRevelationsCommit(ProtocolHandler protocol) : base(protocol) { }
public CycleCommit(ProtocolHandler protocol) : base(protocol) { }
public DoubleEndorsingCommit(ProtocolHandler protocol) : base(protocol) { }
internal AlarmSubscription(ProtocolHandler ph, CallbackHandler <S7AlarmIndicationDatagram> cbh) { ProtocolHandler = ph; CallbackHandler = cbh; }
BakingRightsCommit(ProtocolHandler protocol) : base(protocol) { }
InvoiceMigration(ProtocolHandler protocol) : base(protocol) { }
public BlockCommit(ProtocolHandler protocol) : base(protocol) { }
/// <summary> /// Start a new Client /// </summary> private static void InitializeClient() { SessionToken session = new SessionToken(); ProtocolHandler.LoginResult result = ProtocolHandler.LoginResult.LoginRequired; if (Settings.Password == "-") { Translations.WriteLineFormatted("mcc.offline"); result = ProtocolHandler.LoginResult.Success; session.PlayerID = "0"; session.PlayerName = Settings.Login; } else { // Validate cached session or login new session. if (Settings.SessionCaching != CacheType.None && SessionCache.Contains(Settings.Login.ToLower())) { session = SessionCache.Get(Settings.Login.ToLower()); result = ProtocolHandler.GetTokenValidation(session); if (result != ProtocolHandler.LoginResult.Success) { Translations.WriteLineFormatted("mcc.session_invalid"); if (Settings.Password == "") { RequestPassword(); } } else { ConsoleIO.WriteLineFormatted(Translations.Get("mcc.session_valid", session.PlayerName)); } } if (result != ProtocolHandler.LoginResult.Success) { Translations.WriteLine("mcc.connecting", Settings.AccountType == ProtocolHandler.AccountType.Mojang ? "Minecraft.net" : "Microsoft"); result = ProtocolHandler.GetLogin(Settings.Login, Settings.Password, Settings.AccountType, out session); if (result == ProtocolHandler.LoginResult.Success && Settings.SessionCaching != CacheType.None) { SessionCache.Store(Settings.Login.ToLower(), session); } } } if (result == ProtocolHandler.LoginResult.Success) { Settings.Username = session.PlayerName; bool isRealms = false; if (Settings.ConsoleTitle != "") { Console.Title = Settings.ExpandVars(Settings.ConsoleTitle); } if (Settings.playerHeadAsIcon) { ConsoleIcon.setPlayerIconAsync(Settings.Username); } if (Settings.DebugMessages) { Translations.WriteLine("debug.session_id", session.ID); } List <string> availableWorlds = new List <string>(); if (Settings.MinecraftRealmsEnabled && !String.IsNullOrEmpty(session.ID)) { availableWorlds = ProtocolHandler.RealmsListWorlds(Settings.Username, session.PlayerID, session.ID); } if (Settings.ServerIP == "") { Translations.Write("mcc.ip"); string addressInput = Console.ReadLine(); if (addressInput.StartsWith("realms:")) { if (Settings.MinecraftRealmsEnabled) { if (availableWorlds.Count == 0) { HandleFailure(Translations.Get("error.realms.access_denied"), false, ChatBot.DisconnectReason.LoginRejected); return; } int worldIndex = 0; string worldId = addressInput.Split(':')[1]; if (!availableWorlds.Contains(worldId) && int.TryParse(worldId, out worldIndex) && worldIndex < availableWorlds.Count) { worldId = availableWorlds[worldIndex]; } if (availableWorlds.Contains(worldId)) { string RealmsAddress = ProtocolHandler.GetRealmsWorldServerAddress(worldId, Settings.Username, session.PlayerID, session.ID); if (RealmsAddress != "") { addressInput = RealmsAddress; isRealms = true; Settings.ServerVersion = MCHighestVersion; } else { HandleFailure(Translations.Get("error.realms.server_unavailable"), false, ChatBot.DisconnectReason.LoginRejected); return; } } else { HandleFailure(Translations.Get("error.realms.server_id"), false, ChatBot.DisconnectReason.LoginRejected); return; } } else { HandleFailure(Translations.Get("error.realms.disabled"), false, null); return; } } Settings.SetServerIP(addressInput); } //Get server version int protocolversion = 0; ForgeInfo forgeInfo = null; if (Settings.ServerVersion != "" && Settings.ServerVersion.ToLower() != "auto") { protocolversion = Protocol.ProtocolHandler.MCVer2ProtocolVersion(Settings.ServerVersion); if (protocolversion != 0) { ConsoleIO.WriteLineFormatted(Translations.Get("mcc.use_version", Settings.ServerVersion, protocolversion)); } else { ConsoleIO.WriteLineFormatted(Translations.Get("mcc.unknown_version", Settings.ServerVersion)); } if (useMcVersionOnce) { useMcVersionOnce = false; Settings.ServerVersion = ""; } } //Retrieve server info if version is not manually set OR if need to retrieve Forge information if (!isRealms && (protocolversion == 0 || Settings.ServerAutodetectForge || (Settings.ServerForceForge && !ProtocolHandler.ProtocolMayForceForge(protocolversion)))) { if (protocolversion != 0) { Translations.WriteLine("mcc.forge"); } else { Translations.WriteLine("mcc.retrieve"); } if (!ProtocolHandler.GetServerInfo(Settings.ServerIP, Settings.ServerPort, ref protocolversion, ref forgeInfo)) { HandleFailure(Translations.Get("error.ping"), true, ChatBots.AutoRelog.DisconnectReason.ConnectionLost); return; } } //Force-enable Forge support? if (!isRealms && Settings.ServerForceForge && forgeInfo == null) { if (ProtocolHandler.ProtocolMayForceForge(protocolversion)) { Translations.WriteLine("mcc.forgeforce"); forgeInfo = ProtocolHandler.ProtocolForceForge(protocolversion); } else { HandleFailure(Translations.Get("error.forgeforce"), true, ChatBots.AutoRelog.DisconnectReason.ConnectionLost); return; } } //Proceed to server login if (protocolversion != 0) { try { //Start the main TCP client if (Settings.SingleCommand != "") { client = new McClient(session.PlayerName, session.PlayerID, session.ID, Settings.ServerIP, Settings.ServerPort, protocolversion, forgeInfo, Settings.SingleCommand); } else { client = new McClient(session.PlayerName, session.PlayerID, session.ID, protocolversion, forgeInfo, Settings.ServerIP, Settings.ServerPort); } //Update console title if (Settings.ConsoleTitle != "") { Console.Title = Settings.ExpandVars(Settings.ConsoleTitle); } } catch (NotSupportedException) { HandleFailure(Translations.Get("error.unsupported"), true); } } else { HandleFailure(Translations.Get("error.determine"), true); } } else { string failureMessage = Translations.Get("error.login"); string failureReason = ""; switch (result) { case ProtocolHandler.LoginResult.AccountMigrated: failureReason = "error.login.migrated"; break; case ProtocolHandler.LoginResult.ServiceUnavailable: failureReason = "error.login.server"; break; case ProtocolHandler.LoginResult.WrongPassword: failureReason = "error.login.blocked"; break; case ProtocolHandler.LoginResult.InvalidResponse: failureReason = "error.login.response"; break; case ProtocolHandler.LoginResult.NotPremium: failureReason = "error.login.premium"; break; case ProtocolHandler.LoginResult.OtherError: failureReason = "error.login.network"; break; case ProtocolHandler.LoginResult.SSLError: failureReason = "error.login.ssl"; break; case ProtocolHandler.LoginResult.UserCancel: failureReason = "error.login.cancel"; break; default: failureReason = "error.login.unknown"; break; } failureMessage += Translations.Get(failureReason); if (result == ProtocolHandler.LoginResult.SSLError && isUsingMono) { Translations.WriteLineFormatted("error.login.ssl_help"); return; } HandleFailure(failureMessage, false, ChatBot.DisconnectReason.LoginRejected); } }
public VotingCommit(ProtocolHandler protocol) : base(protocol) { }
/// <summary> /// Registers a callback, so that if a packet arrives that matches the given xpath expression, /// the callback fires. Use <see cref="AddNamespace"/> to add namespace prefixes. /// </summary> /// <example>jc.AddCallback("self::iq[@type='result']/roster:query", new ProtocolHandler(GotRoster));</example> /// <param name="xpath">The xpath expression to search for</param> /// <param name="cb">The callback to call when the xpath matches</param> /// <returns>A guid that can be used to unregister the callback</returns> public Guid AddCallback(string xpath, ProtocolHandler cb) { CallbackData cbd = new CallbackData(xpath, cb); m_callbacks.Add(cbd); return cbd.Guid; }
public CallbackData(string xpath, ProtocolHandler cb) { Debug.Assert(cb != null); m_cb = cb; m_xpath = xpath; }
public ServerBrowser(MainWindow mainWindow, ProtocolHandler ph) { InitializeComponent(); this.ph = ph; MainWindow = mainWindow; }