Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?lc
- function connect_to_db
- put revOpenDatabase("mysql","localhost","lc137543_playlanddb","lc137543_aram","playland1234") into t_id
- if t_id is a number then
- return t_id
- else
- return -1
- end if
- end connect_to_db
- put connect_to_db() into t_conn_id
- if t_conn_id<0 then
- put "error: connecting to database."
- else
- put $_GET["userid"] into t_uid
- put $_GET["action"] into t_action
- put $_GET["value"] into t_val
- if t_uid is empty then
- put "error: you must set userid."
- else
- switch (t_action)
- -- user logged in
- case "login"
- -- add user to db, with action "online" and value NULL
- -- put "insert into actions values("&(t_uid)&",'online','NULL') on dublicate update key userid=userid" into t_query
- --put "if not exists(select userid from actions where userid="&t_uid&") insert into actions values("&(t_uid)&",'online','NULL')" into t_query
- put "select userid from actions where userid="&t_uid into t_query
- put revDataFromQuery("|",return,t_conn_id,t_query) into t_ret
- if t_ret is empty then
- put "insert into actions(userid,username,action,value) values("&(t_uid)&","&(t_val)&",'online','NULL')" into t_query
- end if
- revExecuteSQL t_conn_id,t_query
- break
- -- user logged out
- case "logout"
- -- remove user from db
- put "delete from actions where userid="&(t_uid) into t_query
- revExecuteSQL t_conn_id,t_query
- break
- case "chat"
- -- check if the user is logged in
- put "select userid from actions where userid="&t_uid into t_query
- put revDataFromQuery("|",return,t_conn_id,t_query) into t_ret
- if t_ret is empty then
- put "error: you must be logged in."
- else
- -- set the action of the user to chat and set the value to the message
- put "update actions set action='chat',value='"&t_val&"' where userid="&t_uid into t_query
- revExecuteSQL t_conn_id,t_query
- end if
- break
- case "status"
- -- return statuses for all the users
- --
- break
- default
- put "error: unknown action."
- break
- end switch
- end if
- end if
- -- sending back status after each request
- put "select * from actions" into t_query
- put revDataFromQuery("|",return,t_conn_id,t_query)
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement