diff options
author | Armin Weatherwax | 2009-06-26 09:39:58 +0200 |
---|---|---|
committer | Armin Weatherwax | 2009-07-11 13:42:35 +0200 |
commit | 7067b31a6114089217e482bfecc58fd56bed4272 (patch) | |
tree | e0bb99a42c64cdb75e9ca15a38bc1171377c7739 /linden/indra/newview/controllerlogin.cpp | |
parent | Updated URL for Mac OpenAL libs package. (diff) | |
download | meta-impy-7067b31a6114089217e482bfecc58fd56bed4272.zip meta-impy-7067b31a6114089217e482bfecc58fd56bed4272.tar.gz meta-impy-7067b31a6114089217e482bfecc58fd56bed4272.tar.bz2 meta-impy-7067b31a6114089217e482bfecc58fd56bed4272.tar.xz |
BROKEN logoff/relog crashing inconsistently on various startup states.
Diffstat (limited to '')
-rw-r--r-- | linden/indra/newview/controllerlogin.cpp | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/linden/indra/newview/controllerlogin.cpp b/linden/indra/newview/controllerlogin.cpp new file mode 100644 index 0000000..9dd61a6 --- /dev/null +++ b/linden/indra/newview/controllerlogin.cpp | |||
@@ -0,0 +1,142 @@ | |||
1 | /* | ||
2 | * controllerlogin.cpp | ||
3 | * SecondLife | ||
4 | * | ||
5 | * Created by RMS on 7/16/08. | ||
6 | * | ||
7 | */ | ||
8 | #include "llerror.h" | ||
9 | #include "llmd5.h" | ||
10 | #include <boost/bind.hpp> | ||
11 | #include "controllerlogin.h" | ||
12 | |||
13 | LoginController::LoginController(LoginFloater *floater, AuthenticationModel *authModel, const std::string &grid) | ||
14 | : mFloater(floater), mModel(authModel), mGrid(grid) | ||
15 | { | ||
16 | // set up the user interface subview pointers | ||
17 | name_combo = mFloater->getChild<LLComboBox>("name_combo"); | ||
18 | password_edit = mFloater->getChild<LLLineEditor>("password_edit"); | ||
19 | start_location_combo= mFloater->getChild<LLComboBox>("start_location_combo"); | ||
20 | remember_check = mFloater->getChild<LLCheckBoxCtrl>("remember_check"); | ||
21 | connect_btn = mFloater->getChild<LLButton>("connect_btn"); | ||
22 | quit_btn = mFloater->getChild<LLButton>("quit_btn"); | ||
23 | server_combo = mFloater->getChild<LLComboBox>("server_combo"); | ||
24 | |||
25 | // callbacks | ||
26 | // TODO: account creation and version information callbacks | ||
27 | name_combo->setCommitCallback(onCommitName); | ||
28 | name_combo->setCallbackUserData(this); | ||
29 | password_edit->setCommitCallback(onCommitPassword); | ||
30 | password_edit->setCallbackUserData(mFloater); | ||
31 | connect_btn->setClickedCallback(onAccept, this); | ||
32 | quit_btn->setClickedCallback(onCancel, this); | ||
33 | |||
34 | // subscribe to the model | ||
35 | mModelConnection = mModel->subscribeToModelUpdates(boost::bind(&LoginController::update, this)); | ||
36 | // request an initial update | ||
37 | mModel->requestUpdate(); | ||
38 | } | ||
39 | |||
40 | LoginController::~LoginController() | ||
41 | { | ||
42 | mModel->unsubscribe(mModelConnection); | ||
43 | } | ||
44 | |||
45 | void LoginController::update() | ||
46 | { | ||
47 | // when we want to update, we need to make sure it's relevant to our | ||
48 | // interests and make the change as smooth as possible for the user | ||
49 | std::set<std::string> newAccountNames; | ||
50 | mModel->getAccountNames(mGrid, newAccountNames); | ||
51 | |||
52 | if(mAccountNames == newAccountNames) | ||
53 | return; | ||
54 | |||
55 | name_combo->removeall(); | ||
56 | |||
57 | for(std::set<std::string>::iterator it = newAccountNames.begin(); | ||
58 | it != newAccountNames.end(); ++it) | ||
59 | { | ||
60 | name_combo->add(*it); | ||
61 | } | ||
62 | |||
63 | name_combo->sortByName(); | ||
64 | mAccountNames.swap(newAccountNames); | ||
65 | } | ||
66 | |||
67 | void LoginController::mungePassword(std::string &password) | ||
68 | { | ||
69 | LLMD5 pass((unsigned char *)password.c_str()); | ||
70 | char munged_password[MD5HEX_STR_SIZE]; | ||
71 | pass.hex_digest(munged_password); | ||
72 | password = munged_password; | ||
73 | } | ||
74 | |||
75 | // user interface callbacks | ||
76 | |||
77 | void LoginController::onCommitName(LLUICtrl *control, void *userdata) | ||
78 | { | ||
79 | // look at this shit it fills in the password box if it finds a stored account | ||
80 | // and auto checks remember password | ||
81 | LoginController *controller = (LoginController *)userdata; | ||
82 | LoginFloater *floater = controller->mFloater; | ||
83 | |||
84 | std::string loginname = floater->childGetText("name_combo"); | ||
85 | std::set<std::string>::iterator it = controller->mAccountNames.find(loginname); | ||
86 | if(it != controller->mAccountNames.end()) | ||
87 | { | ||
88 | std::string loginpassword; | ||
89 | |||
90 | controller->mModel->getPassword(controller->mGrid, loginname, loginpassword); | ||
91 | LoginFloater::setFields(loginname, loginpassword, true); | ||
92 | } | ||
93 | } | ||
94 | |||
95 | void LoginController::onCommitPassword(LLUICtrl *control, void *userdata) | ||
96 | { | ||
97 | LoginFloater *floater = (LoginFloater *)userdata; | ||
98 | LLLineEditor *editor = (LLLineEditor *)control; | ||
99 | std::string password = editor->getText(); | ||
100 | |||
101 | // when we have a new password we need to MD5 it and tell the floater | ||
102 | if(!floater->isSamePassword(password)) | ||
103 | { | ||
104 | mungePassword(password); | ||
105 | floater->setPassword(password); | ||
106 | } | ||
107 | } | ||
108 | |||
109 | void LoginController::onAccept(void* userdata) | ||
110 | { | ||
111 | // this here does the main work of telling the model we need to write | ||
112 | // account data | ||
113 | LoginController *controller = (LoginController *)userdata; | ||
114 | LoginFloater *floater = controller->mFloater; | ||
115 | |||
116 | if(!floater->childGetValue("remember_check")) | ||
117 | { | ||
118 | LoginFloater::accept(); | ||
119 | return; | ||
120 | } | ||
121 | |||
122 | std::string username = floater->childGetText("name_combo"); | ||
123 | std::string password = floater->getPassword(); | ||
124 | |||
125 | if(controller->mAccountNames.find(username) != controller->mAccountNames.end()) | ||
126 | { | ||
127 | controller->mModel->changePassword(controller->mGrid, username, password); | ||
128 | } | ||
129 | |||
130 | else | ||
131 | { | ||
132 | controller->mModel->addAccount(controller->mGrid, username, password); | ||
133 | } | ||
134 | controller->mModel->savePersistentData(); | ||
135 | LoginFloater::accept(); | ||
136 | } | ||
137 | |||
138 | void LoginController::onCancel(void* userdata) | ||
139 | { | ||
140 | // if the user backs out of the dialog we tell it to clean up and such | ||
141 | LoginFloater::cancel_old(); | ||
142 | } | ||