private void bPlay_Click(object sender, RoutedEventArgs e) { XmlUserCredentials xu = new XmlUserCredentials() { Name = cbxLoginName.Text, Password = txtPassword.Text}; Server.Instance.JoinCompleted += new EventHandler<JoinCompletedEventArgs>(Proxy_JoinCompleted); // set ui status on logging in spLoginStatus.Visibility = Visibility.Visible; btnPlay.IsEnabled = false; spinLoginStatus.Visibility = Visibility.Visible; Server.Instance.JoinAsync(xu); }
public XmlUser Authenticate(XmlUserCredentials credentials) { string password = GetSHA1(credentials.Password); var users = (from u in Core.Instance.Entities.User where (u.Name.ToLower() == credentials.Name.ToLower() && password.Equals(u.PasswordHash)) select u); if (users.Count() == 0) return null; if (users.Count() == 1) { return users.First().BuildXmlUser(); } else { return null; } }
/// <summary> /// Takes a <see cref="Common.Person">Person</see> and allows them /// to join the chat room, if there is not already a chatter with /// the same name /// </summary> /// <param name="person"><see cref="Common.Person">Person</see> joining</param> /// <returns>An array of <see cref="Common.Person">Person</see> objects</returns> public JoinResult Join(XmlUserCredentials person) { MessageFromServerAction message = new MessageFromServerAction(); message.Sender = _ServerUser.ID; if (person == null) { message.Message = "No valid person passed (Usercredentials object == null)"; return new JoinResult() { FailMessage = message }; } if (String.IsNullOrEmpty(person.Name) || String.IsNullOrEmpty(person.Password)) { message.Message = "either password or username isnt valid: empty password or username"; return new JoinResult() { FailMessage = message }; } /* XmlUser user = _UserAdministration.Authenticate(person); // we failed to authenticate, communicate this back to user if (user == null) { message.Message = "either password or username isnt valid, or both"; return new JoinResult() { FailMessage = message }; } */ //Yey! we are authenticated. Add user to list of users and // return the lobby state bool userAdded = false; //create a new ChatEventHandler delegate, pointing to the MyEventHandler() method myEventHandler = new GameEventHandler(MyEventHandler); //carry out a critical section that checks to see if the new chatter //name is already in use, if its not allow the new chatter to be //added to the list of chatters, using the person as the key, and the //ChatEventHandler delegate as the value, for later invocation lock (threadSync) { /* if (!PlayerExists(user.ID)) { _Users.Add(user, MyEventHandler); userAdded = true; _CurrentPerson = user; } else { message.Message = "It seems that you are already logged in."; return new JoinResult() { FailMessage = message }; } */ } //if the new chatter could be successfully added, get a callback instance //create a new message, and broadcast it to all other chatters, and then //return the list of al chatters such that connected clients may show a //list of all the chatters if (userAdded) { _Callback = OperationContext.Current.GetCallbackChannel<IChatCallback>(); //add this newly joined chatters ChatEventHandler delegate, to the global //multicast delegate for invocation ChatEvent += myEventHandler; XmlLobbyState lobbyState = new XmlLobbyState(); //carry out a critical section that copy all chatters to a new list lock (threadSync) { //copy chatlog if (_LobbyChatLog != null) { lobbyState.LobbyChat = _LobbyChatLog.Copy(); } //copy users if (_Users != null) { lobbyState.Users = new List<XmlUser>(); foreach (KeyValuePair<XmlUser, GameEventHandler> lobbyUser in _Users) lobbyState.Users.Add(lobbyUser.Key.Copy()); } //copy games if (_Games != null) { lobbyState.Games = CreateGameList(); } } /* //Say to all other players we have a new player joined in the lobby LobbyJoinedAction lobbyJoined = new LobbyJoinedAction() { NewPlayer = user, Sender = _ServerUser.ID }; BroadcastMessage(lobbyJoined, user); return new JoinResult() { User = user, LobbyState = lobbyState }; */ return null; } else { message.Message = "You are already in the list of logged in players!"; message.Sender = _ServerUser.ID; return null; } }
// Since we act as a proxy between the client and the network or hotseat // server, we bubble through all calls to the current proxy public JoinResult Join(XmlUserCredentials credentials) { return _Proxy.Join(credentials); }
public IAsyncResult BeginJoin(XmlUserCredentials credentials, AsyncCallback callback, object asyncState) { return _Proxy.BeginJoin(credentials, callback, asyncState); }
public JoinResult Join(XmlUserCredentials credentials) { throw new NotImplementedException(); }
public IAsyncResult BeginJoin(XmlUserCredentials credentials, AsyncCallback callback, object asyncState) { throw new NotImplementedException(); }