Architecture overview - olegrok/Messenger GitHub Wiki
Сlient-Server interaction.
Small description
- To work with the server, each client must get a session token. The token contains information confirming the user's rights to perform actions associated with the account. Without authentication you have opportunity to registration and authorization.
Commands
- Authorization
- Registration
- Logout
- Add contact
- Delete contact
- Send a message
JSON requests and replies (in case of success*)
##Account requests
- Authorization and registration
{ "request":"property*" , "login":"_login_" , "password":"_password_" }
property:
- Authorization:
In case of correct data, the response contains the session token- Registration:
Does not return any data
reply:
session = { "contact_uid":"_uid_" , "session_key":"_key_" }
- Logout
{ "request":"logout" , "session":{ "uid":"_uid_" , "session_key":"_key_" } }
- The master data request
To start , the client should ask the server for some data
*currently, the client data:friends list
{ "request":"get_data" , "session":{"uid":"_uid_" , "session_key":"_cookie_" } }
reply:
{ "contacts":{"friend_login":"_login_", "friend_uid":"_uid_", "status":"[1, 2, 3]"} , "settings":[] }
Contacts
There are four types contacts in the contact list (numbers in list coincide with "contact status"):
- Those who you have sent a request for friend.
- Added to friends.
- Contacts rejected your application.
- The applications that have been sent to you.
- Add contact
{ "request":"add_contact_request" , "login":”_login_” , “session”:{} }
reply:
{ "uid":"_uid_" , "status":”[1, 2, 3]” , “session”:{} }
statuses:
Outgoing = 0
Accepted = 1
Denied = 2
Incoming = 3
- Confirm add a contact
{"request": "add_contact_reply", "contact_uid": "_uid_", "status": "_ReplyStatus_", "session": "[...]"}
There are four reply statuses
Request = 0
Accepted = 1
Denied = 2
Cancel = 3
- Delete contact
{ "request":"del_contact" , "login":"_login_" }
- Send a message
You can send a message only to your friend
{ "request":"send_msg" , "to_uid":"_uid_" , "msg":"_text_" , “session”:{...} }
Updates
{ "request": "update_data" , "last_time": "time_in_seconds_UNIX_format", "session":"[...]" }
reply:
{ "msg_array": [ { "sender_uid":"Nil" , "sender_login":"Nil" , "messages": { "time":"Nil" , "text":"Nil" } ], "events_array": [{"eid":"event_id", "type":"type", "ruid":"requester_id", "text":"text"}] }
* - success:
reply status code = 200
HTTP status codes