the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 95 lines 2.9 kB view raw
1#include "stdafx.h" 2#include "ConnectScreen.h" 3#include "ClientConnection.h" 4#include "TitleScreen.h" 5#include "Button.h" 6#include "Minecraft.h" 7#include "User.h" 8#include "..\Minecraft.World\net.minecraft.locale.h" 9 10 11ConnectScreen::ConnectScreen(Minecraft *minecraft, const wstring& ip, int port) 12{ 13 aborted = false; 14// System.out.println("Connecting to " + ip + ", " + port); 15 minecraft->setLevel(NULL); 16#if 1 17 // 4J - removed from separate thread, but need to investigate what we actually need here 18 connection = new ClientConnection(minecraft, ip, port); 19 if (aborted) return; 20 connection->send( shared_ptr<PreLoginPacket>( new PreLoginPacket(minecraft->user->name) ) ); 21#else 22 23 new Thread() { 24 public void run() { 25 26 try { 27 connection = new ClientConnection(minecraft, ip, port); 28 if (aborted) return; 29 connection.send(new PreLoginPacket(minecraft.user.name)); 30 } catch (UnknownHostException e) { 31 if (aborted) return; 32 minecraft.setScreen(new DisconnectedScreen("connect.failed", "disconnect.genericReason", "Unknown host '" + ip + "'")); 33 } catch (ConnectException e) { 34 if (aborted) return; 35 minecraft.setScreen(new DisconnectedScreen("connect.failed", "disconnect.genericReason", e.getMessage())); 36 } catch (Exception e) { 37 if (aborted) return; 38 e.printStackTrace(); 39 minecraft.setScreen(new DisconnectedScreen("connect.failed", "disconnect.genericReason", e.toString())); 40 } 41 } 42 }.start(); 43#endif 44} 45 46void ConnectScreen::tick() 47{ 48 if (connection != NULL) 49 { 50 connection->tick(); 51 } 52} 53 54void ConnectScreen::keyPressed(char eventCharacter, int eventKey) 55{ 56} 57 58void ConnectScreen::init() 59{ 60 Language *language = Language::getInstance(); 61 62 buttons.clear(); 63 buttons.push_back(new Button(0, width / 2 - 100, height / 4 + 24 * 5 + 12, language->getElement(L"gui.cancel"))); 64 65} 66 67void ConnectScreen::buttonClicked(Button *button) 68{ 69 if (button->id == 0) 70 { 71 aborted = true; 72 if (connection != NULL) connection->close(); 73 minecraft->setScreen(new TitleScreen()); 74 } 75} 76 77void ConnectScreen::render(int xm, int ym, float a) 78{ 79 renderBackground(); 80 81 Language *language = Language::getInstance(); 82 83 if (connection == NULL) 84 { 85 drawCenteredString(font, language->getElement(L"connect.connecting"), width / 2, height / 2 - 50, 0xffffff); 86 drawCenteredString(font, L"", width / 2, height / 2 - 10, 0xffffff); 87 } 88 else 89 { 90 drawCenteredString(font, language->getElement(L"connect.authorizing"), width / 2, height / 2 - 50, 0xffffff); 91 drawCenteredString(font, connection->message, width / 2, height / 2 - 10, 0xffffff); 92 } 93 94 Screen::render(xm, ym, a); 95}