| 1 | //load( "components.asc" ); |
|---|
| 2 | application.onAppStart = function() |
|---|
| 3 | { |
|---|
| 4 | now_date = new Date(); |
|---|
| 5 | // Get the server shared object 'users_so' and 'list_so' |
|---|
| 6 | application.users_so = SharedObject.get("users_so", false); |
|---|
| 7 | application.nextId = 100; |
|---|
| 8 | application.history = "<font color='#990000'>("+now_date+ ") Application Started</font>"; |
|---|
| 9 | trace(application.history) |
|---|
| 10 | } |
|---|
| 11 | |
|---|
| 12 | //when someone connects to the application(a room) |
|---|
| 13 | application.onConnect = function(newClient,name,money,purpose) |
|---|
| 14 | { |
|---|
| 15 | |
|---|
| 16 | if (name=="guest") |
|---|
| 17 | { |
|---|
| 18 | newClient.name ="guest"+application.nextId |
|---|
| 19 | money=0; |
|---|
| 20 | application.nextId++; |
|---|
| 21 | }else{ |
|---|
| 22 | newClient.name=name; |
|---|
| 23 | } |
|---|
| 24 | |
|---|
| 25 | newClient.id=application.nextId; |
|---|
| 26 | |
|---|
| 27 | if (purpose!="record") |
|---|
| 28 | { |
|---|
| 29 | var PeopleObj = new Object(); |
|---|
| 30 | PeopleObj.name = newClient.name; |
|---|
| 31 | PeopleObj.money = money; |
|---|
| 32 | PeopleObj.status = "offline"; |
|---|
| 33 | //PeopleObj.status = "online"; |
|---|
| 34 | PeopleObj.id = newClient.id; |
|---|
| 35 | application.users_so.setProperty(PeopleObj.id,PeopleObj); |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | application.nextId++; |
|---|
| 39 | |
|---|
| 40 | // Accept the client's connection |
|---|
| 41 | application.acceptConnection(newClient); |
|---|
| 42 | |
|---|
| 43 | //Update the history log |
|---|
| 44 | if(newClient.name!="administrator") |
|---|
| 45 | { |
|---|
| 46 | now_date = new Date(); |
|---|
| 47 | application.history += "<br>("+ now_date + ") "+ newClient.name + " joined the chat." |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | //send the log to the admin |
|---|
| 51 | newClient.call("setHistory",null,application.history); |
|---|
| 52 | |
|---|
| 53 | //function below |
|---|
| 54 | newClient.requestPrivateSrvr = function(username, pmode) |
|---|
| 55 | { |
|---|
| 56 | now_date = new Date(); |
|---|
| 57 | application.history += "<br>("+ now_date + ") "+ username + " requested private chat, mode:" + pmode + "." |
|---|
| 58 | application.users_so.send("requestPrivate", username, pmode); |
|---|
| 59 | }; |
|---|
| 60 | |
|---|
| 61 | newClient.leavePrivateSrvr = function (username) |
|---|
| 62 | { |
|---|
| 63 | now_date = new Date(); |
|---|
| 64 | application.history += "<br>("+ now_date + ") "+ username + " left private chat." |
|---|
| 65 | application.users_so.send("leavePrivate", username); |
|---|
| 66 | }; |
|---|
| 67 | |
|---|
| 68 | newClient.sendTip = function(ammount,from) |
|---|
| 69 | { |
|---|
| 70 | now_date = new Date(); |
|---|
| 71 | application.history += "<br>("+ now_date + ") "+ from + " tipped the model with " + ammount/100 + "$. " |
|---|
| 72 | application.users_so.send("recieveTip",ammount,from); |
|---|
| 73 | }; |
|---|
| 74 | |
|---|
| 75 | newClient.msgFromClient = function(msg) |
|---|
| 76 | { |
|---|
| 77 | trace("messagefrom client"); |
|---|
| 78 | |
|---|
| 79 | msg="<b>"+newClient.name+"</b>!!"+msg; |
|---|
| 80 | arContents = new Array(); |
|---|
| 81 | arContents = msg.split("!!"); |
|---|
| 82 | |
|---|
| 83 | now_date = new Date(); |
|---|
| 84 | application.history += "<br>("+ now_date + ") "+arContents[0]+":"+arContents[2]; |
|---|
| 85 | application.users_so.send("msgFromSrvr", msg); |
|---|
| 86 | }; |
|---|
| 87 | |
|---|
| 88 | newClient.changeStatus = function(status) |
|---|
| 89 | { |
|---|
| 90 | PeopleObj.status = status; |
|---|
| 91 | trace(status); |
|---|
| 92 | application.users_so.setProperty(PeopleObj.id,PeopleObj); |
|---|
| 93 | trace(); |
|---|
| 94 | }; |
|---|
| 95 | |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | application.onDisconnect = function(client) |
|---|
| 99 | { |
|---|
| 100 | var personObj= application.users_so.getProperty(client.id); |
|---|
| 101 | if (personObj.name!="administrator") |
|---|
| 102 | { |
|---|
| 103 | now_date = new Date(); |
|---|
| 104 | application.history += "<br>("+ now_date + ") "+ personObj.name + " left the chat." |
|---|
| 105 | } |
|---|
| 106 | application.users_so.setProperty(client.id, null); |
|---|
| 107 | |
|---|
| 108 | } |
|---|