public void Process(Context context) { var user = context.Server.Database.QueryUser(Username); if (user != null) { if (user.Password != Password) { context.SendAndProcessMessage(new LoginFailure()); return; } } else { user = context.Server.Database.InsertUser(Username, Password, context.Salt); } // Remove any older sessions from this user (duplicate logins) var otherSession = context.Server.GetSession(user); if (otherSession != null) { context.Server.RemoveSession(otherSession); otherSession.TcpClient.Close(); } context.User = user; var success = new LoginSuccess(); context.SendAndProcessMessage(success); }
// TODO: Create test for this message so we can refactor and build this message the same way as the others to avoid the switch statement // TODO: How to tell the client we didn't receive the ACK? // TODO: P2P stuff??? public void Process(Context context) { var otherSession = context.Server.GetSession(SessionId); var messageType = (byte)MessagePayload["msgtype"]; switch (messageType) { case 0: var responseAck = BuildAckResponse(otherSession.SessionId); context.SendMessage(responseAck); var chatMsg = BuildChatMessageResponse(context.SessionId); otherSession.SendMessage(chatMsg); break; case 1: Debug.WriteLine("NOT BUILT: Got ACK for session " + context.SessionId); break; case 2: Debug.WriteLine("NOT BUILT: Got P2P info for session " + context.SessionId); break; case 3: var typingMsg = BuildChatMessageResponse(context.SessionId); otherSession.SendMessage(typingMsg); break; } }
public void Process(Context context) { var requseterUser = context.Server.Database.QueryUser(RequesterUsername); var pendingRequests = context.Server.Database.QueryPendingFriendRequestsSelf(requseterUser); var requestsIds = pendingRequests.Where(a => a.UserId == requseterUser.UserId && a.FriendUserId == context.User.UserId) .Select(a => a.PendingFriendRequestId).ToArray(); context.Server.Database.DeletePendingFriendRequest(requestsIds); }
public void Process(Context context) { var friends = context.Server.Database.QueryFriends(owner); friends.ForEach(f => { UserIds.Add(f.UserId); Usernames.Add(f.Username); Nicks.Add(f.Nickname); }); }
public int AddSession(Context session) { if (sessions.ContainsKey(session.SessionId)) { Debug.WriteLine("Tried to add a user with session id {0} that already existed", "WARN", session.SessionId); return -1; } sessions.Add(session.SessionId, session); return sessions.Count; }
private async Task Receive(Context context) { var stream = context.TcpClient.GetStream(); while (running) { // First time the client connects, an opening statement of 4 bytes is sent that needs to be ignored if (!context.Initialized) { var openingStatementBuffer = new byte[4]; await stream.ReadAsync(openingStatementBuffer, 0, openingStatementBuffer.Length); context.InitializeClient(); } // Header determines size of message var headerBuffer = new byte[2]; var read = await stream.ReadAsync(headerBuffer, 0, headerBuffer.Length); if (read == 0) { if (OnDisconnection != null) { OnDisconnection(context); } break; } var messageLength = BitConverter.ToInt16(headerBuffer, 0) - headerBuffer.Length; var messageBuffer = new byte[messageLength]; read = await stream.ReadAsync(messageBuffer, 0, messageLength); Debug.WriteLine("RECEIVED RAW: " + BitConverter.ToString(messageBuffer)); try { IMessage message = MessageSerializer.Deserialize(messageBuffer); Console.WriteLine("Recv message[{0},{1}]: {2}", context.User != null ? context.User.Username : "******", context.User != null ? context.User.UserId : -1, message); if (OnReceive != null) { OnReceive(context, message); } } catch (UnknownMessageTypeException messageTypeEx) { Debug.WriteLine(messageTypeEx.ToString()); } catch (UnknownXFireAttributeTypeException attributeTypeEx) { Debug.WriteLine(attributeTypeEx.ToString()); } } }
public void Process(Context context) { var users = context.Server.Database.QueryUsers(queryByUsername); var usernames = users.Select(a => a.Username); Usernames.AddRange(usernames); // Don't really care about these but they're necessary to work properly var unknowns = usernames.Select(a => "Unknown"); FirstNames.AddRange(unknowns); LastNames.AddRange(unknowns); Emails.AddRange(unknowns); }
public void Process(Context context) { var statusChange = new FriendStatusChange(context.SessionId, Message); var friends = context.Server.Database.QueryFriends(context.User); friends.ForEach(friend => { var friendSession = context.Server.GetSession(friend); if (friendSession != null) { friendSession.SendAndProcessMessage(statusChange); } }); }
public void Process(Context context) { var recipient = context.Server.Database.QueryUser(Username); var invite = new FriendInvite(context.User.Username, context.User.Nickname, Message); invite.Process(context); context.Server.Database.InsertFriendRequest(context.User, Username, Message); var recipientSession = context.Server.GetSession(recipient); if (recipientSession != null) { recipientSession.SendMessage(invite); } }
private async Task Accept() { while (running) { Context session = new Context(await listener.AcceptTcpClientAsync().ConfigureAwait(false)); Debug.WriteLine("Client connected {0} and assigned session id {1}", session.TcpClient.Client.RemoteEndPoint, session.SessionId); if (OnConnection != null) { OnConnection(session); } Receive(session); } }
public void Process(Context context) { preferences = new Dictionary<byte, string>(); preferences.Add(1, "0"); preferences.Add(4, "0"); preferences.Add(5, "0"); preferences.Add(6, "1"); preferences.Add(7, "0"); preferences.Add(8, "0"); preferences.Add(11, "0"); preferences.Add(17, "0"); preferences.Add(18, "0"); preferences.Add(19, "0"); preferences.Add(20, "0"); preferences.Add(21, "0"); }
public void Process(Context context) { var friends = context.Server.Database.QueryFriends(owner); // offline friends are just not sent var friendsSessions = friends.Select(a => context.Server.GetSession(a)) .Where(a => a != null) .ToList(); friendsSessions.ForEach(session => { UserIds.Add(session.User.UserId); SessionIds.Add(session.SessionId); Debug.WriteLine("Status: For:{0} -- FriendId:{1} Friend:{2} FriendSession:{3}", context.User.Username, session.User.UserId, session.User.Username, session.SessionId); }); //friendsSessions.OrderBy(a => a.User.UserId); //friendsSessions.ForEach(session => Debug.WriteLine("Context: For:{0} -- FriendId:{1} Friend:{2} FriendSession:{3}", context.User.Username, session.User.UserId, session.User.Username, session.SessionId)); }
public void Process(Context context) { if (Nickname.Length > MAX_LENGTH) { Nickname = Nickname.Substring(0, MAX_LENGTH); } context.Server.Database.UpdateNickname(context.User, Nickname); var updatedFriendsList = new FriendsList(context.User); context.Server.Database.QueryFriends(context.User).ForEach(friend => { var friendSession = context.Server.GetSession(friend); if(friendSession != null) { friendSession.SendAndProcessMessage(updatedFriendsList); } }); }
public void Process(Context context) { var clientPrefs = new Unknown10(); context.SendAndProcessMessage(clientPrefs); var groups = new Groups(); context.SendAndProcessMessage(groups); var groupsFriends = new GroupsFriends(); context.SendAndProcessMessage(groupsFriends); var serverList = new ServerList(); context.SendAndProcessMessage(serverList); var chatRooms = new ChatRooms(); context.SendAndProcessMessage(chatRooms); var friendsList = new FriendsList(context.User); context.SendAndProcessMessage(friendsList); var friendsStatus = new FriendsSessionAssign(context.User); context.SendAndProcessMessage(friendsStatus); // Tell friends this user came online //if (context.User.Username == "test") Debugger.Break(); var friends = context.Server.Database.QueryFriends(context.User); friends.ForEach(friend => { var otherSession = context.Server.GetSession(friend); if (otherSession != null) { otherSession.SendAndProcessMessage(new FriendsSessionAssign(friend)); } }); var pendingFriendRequests = context.Server.Database.QueryPendingFriendRequests(context.User); pendingFriendRequests.ForEach(request => { var requester = context.Server.Database.QueryUser(request.UserId); context.SendAndProcessMessage(new FriendInvite(requester.Username, requester.Nickname, request.Message)); }); }
public void Process(Context context) { var friend = context.Server.Database.QueryUser(FriendUsername); context.Server.Database.InsertMutualFriend(context.User, friend); context.SendAndProcessMessage(new FriendsList(context.User)); context.SendAndProcessMessage(new FriendsSessionAssign(context.User)); // It's possible to accept a friend request where the inviter is not online var friendSession = context.Server.GetSession(friend); if (friendSession != null) { friendSession.SendAndProcessMessage(new FriendsList(friend)); friendSession.SendAndProcessMessage(new FriendsSessionAssign(friend)); } var pendingRequests = context.Server.Database.QueryPendingFriendRequests(context.User); var pq = pendingRequests.FirstOrDefault(a => a.FriendUserId == context.User.UserId); if (pq != null) { context.Server.Database.DeletePendingFriendRequest(pq.PendingFriendRequestId); } }
public void Process(Context context) { ChatIds = new List<int>(); }
public void Process(Context context) { }
public void RemoveSession(Context session) { RemoveSession(session.SessionId); }
public void Process(Context context) { Unknown = new byte[] { 0xd1, 0xc2, 0x95, 0x33, 0x84, 0xc4, 0xcc, 0xb2, 0x31, 0x50, 0x1f, 0x0e, 0x43, 0xc5, 0x89, 0x30, 0xb2, 0xa7, 0x0e, 0x4a, 0xb6 }; }
void OnDisconnection(Context sessionContext) { RemoveSession(sessionContext); var friends = Database.QueryFriends(sessionContext.User); friends.ForEach(friend => { var friendSession = GetSession(friend); if (friendSession != null) { // Not working sessionContext.SendAndProcessMessage(new FriendsSessionAssign(friend)); } }); }
void HandleNewConnection(Context sessionContext) { AddSession(sessionContext); }
public void Process(Context context) { Salt = context.Salt; }
public void Process(Context context) { throw new NotImplementedException(); }
public void Process(Context context) { // Nothing }
public void Process(Context context) { GameIds = new List<int>(); GameIPs = new List<int>(); GamePorts = new List<int>(); }
public void Process(Context context) { var loginChallenge = new LoginChallenge(); loginChallenge.Process(context); context.SendMessage(loginChallenge); }
public void Process(Context context) { UserId = context.User.UserId; SessionId = context.SessionId; Status = 0;//BitConverter.ToInt32(new byte[] { 0x7f, 0x05, 0x0, 0x0 }, 0); Nickname = String.IsNullOrEmpty(context.User.Nickname) ? context.User.Username : context.User.Nickname; MinRect = 1; MaxRect = 164867; var ipAddress = StripPortFromIPAddress(context.TcpClient.Client.RemoteEndPoint.ToString()); PublicIp = BitConverter.ToInt32(IPAddress.Parse(ipAddress).GetAddressBytes(), 0); Salt = context.Salt; Reason = "Mq_P8Ad3aMEUvFinw0ceu6FITnZTWXxg46XU8xHW"; Debug.WriteLine("User {0}[{1}] logged in successfully with session id {2}", context.User.Username, context.User.UserId, context.SessionId); Console.WriteLine("User {0} logged in", context.User.Username); //N1 = BitConverter.ToInt32(new byte[] { 0x3c, 0xb2, 0x58, 0xd0 }, 0); //N2 = BitConverter.ToInt32(new byte[] { 0x3d, 0xb2, 0x58, 0xd0 }, 0); //N3 = BitConverter.ToInt32(new byte[] { 0x3e, 0xb2, 0x58, 0xd0 }, 0); }
void HandleRequest(Context context, IMessage message) { context.Server = this; //Console.WriteLine("Processing: {0}", message.ToString()); message.Process(context); }
public void Process(Context context) { GroupIds = new List<int>(); GroupNames = new List<string>(); }
public void Process(Context context) { var result = new UserLookupResult(Username); context.SendAndProcessMessage(result); }