Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- load("components.asc");
- application.topic = "";
- application.cameraNo = 0;
- application.performer = null;
- application.hash = null;
- application.fmsId = null;
- application.flvName = null;
- application.videoStream;
- application.baseUrl = "http://www.pcheld.nl/arco/chat/";
- application.banUrl = "fms/banmanager";
- application.authUrl = "fms/auth";
- application.authPerformerUrl = "performer/fms/auth";
- application.taxUrl = "fms/tax";
- application.truePrivateUrl = "fms/trueprivate";
- application.endSessionUrl = "fms/endsession";
- application.chatLogUrl = "fms/log";
- application.tipUrl = "fms/tip";
- application.validateChipsUrl = "fms/validatechips";
- application.onAppStart = function()
- {
- trace("onAppStart");
- application.allowDebug = true;
- }
- application.onConnect = function(clientObj, performerId, pasword,
- userId, userType, userName, uniqId, sessionType, md5Check, truePrivate)
- {
- load("hash.as");
- trace("onConnect");
- application.hash = hash;
- application.fmsId = md5Check;
- trace("onConnect, performerId: " + performerId + ", pasword: " +
- pasword + ", userId: " + userId + ", userType: " + userType +
- ", userName: ", userName + ", uniqId: " +
- uniqId + ", sessionType: " + sessionType + ", md5Check: " + md5Check + ", truePrivate: " + truePrivate);
- // Set the number of cameras activated if performer
- if(userType == "performer")
- {
- application.cameraNo = sessionType;
- application.performer = clientObj;
- }
- application.initClient(clientObj);
- clientObj.userId = userId;
- clientObj.releaseStream = function() { trace("releaseStream"); };
- clientObj.FCPublish = function() { trace("FCPublish"); };
- clientObj.FCUnpublish = function() { trace("FCUnpublish"); };
- // TODO: Check if user isnt logged in already
- // Variables
- application.acceptConnection(clientObj);
- clientObj.userType = userType;
- clientObj.userName = userName;
- clientObj.performerId = performerId;
- clientObj.pasword = pasword;
- clientObj.sessionType = sessionType;
- clientObj.uniqId = uniqId;
- clientObj.truePrivate = truePrivate;
- clientObj.md5Check = md5Check;
- if(userType == "viewer" || userType == "performer")
- application.userCheck(clientObj);
- else
- application.initClientInterval(clientObj);
- };
- application.initClient = function(clientObj)
- {
- // Functions
- clientObj.broadcastChatLine = application.broadcastChatLine;
- clientObj.broadcastChatLineIcon = application.broadcastChatLineIcon;
- clientObj.updateTopic = application.updateTopic;
- clientObj.getTopic = application.getTopic;
- clientObj.askForNumberOfCameras = application.askForNumberOfCameras;
- clientObj.ask_song = application.ask_song;
- clientObj.change_song = application.change_song;
- clientObj.send_song = application.send_song;
- clientObj.initializeSpy = application.initializeSpy;
- clientObj.rec = application.rec;
- clientObj.recStop = application.recStop;
- clientObj.kick = application.kick;
- clientObj.ban = application.ban;
- clientObj.kickSelf = application.kickSelf;
- clientObj.banSelf = application.banSelf;
- clientObj.privateInvitation = application.privateInvitation;
- clientObj.acceptInvitation = application.acceptInvitation;
- clientObj.enterPrivate = application.enterPrivate;
- clientObj.changeSessionTypeToPrivate = application.changeSessionTypeToPrivate;
- clientObj.rejectInvitation = application.rejectInvitation;
- clientObj.tipPerfromer = application.tipPerfromer;
- clientObj.setViewerBroadcast = application.setViewerBroadcast;
- clientObj.getFmsVersion = application.getFmsVersion;
- if(clientObj.userType == "viewer")
- {
- clientObj.taxIntervalId = setInterval(application.checkTax, 5000, clientObj);
- }
- trace("User is ACEPTED");
- }
- application.initClientInterval = function(clientObj)
- {
- if(clientObj.userType == "viewer")
- {
- clientObj.taxIntervalId = setInterval(application.checkTax, 5000, clientObj);
- }
- trace("User is ACCEPTED");
- }
- application.checkTax = function(client)
- {
- trace("checkTax " + client.sessionType);
- // Check if the user has session still
- var isLoggedIn = false;
- var clients = application.clients;
- var n = clients.length;
- for(var i = 0; i < n; i++)
- {
- if(clients[i] == client)
- {
- isLoggedIn = true;
- break;
- }
- }
- if(!isLoggedIn)
- clearInterval(client.taxIntervalId);
- var taxSendLV = new LoadVars();
- var taxRecvLV = new LoadVars();
- taxSendLV.userId = client.userId;
- taxSendLV.userType = client.userType;
- taxSendLV.pasword = client.pasword;
- taxSendLV.uniqId = client.uniqId;
- taxSendLV.performerId = client.performerId;
- taxSendLV.truePrivate = client.truePrivate;
- taxSendLV.sessionType = (client.sessionType == "true_private") ? "private" : client.sessionType;
- taxSendLV.hash = application.hash;
- taxSendLV.sendAndLoad(application.baseUrl + application.taxUrl, taxRecvLV, "POST");
- taxRecvLV.onLoad = function(success)
- {
- if (success)
- {
- if (this.status == "allow")
- {
- //trace("Tax allowed " + this.status);
- }
- else
- {
- trace("Tax denied " + this.status);
- application.disconnect(client);
- }
- }
- else
- {
- trace("Call to tax unsuccess");
- }
- }
- }
- application.userCheck = function(client)
- {
- var urlParams = "ip=" + client.ip + "&userId=" + client.userId +
- "&userType=" + client.userType + "&pasword=" + client.pasword +
- "&uniqId=" + client.uniqId + "&userName=" + client.userName +
- "&performerId=" + client.performerId + "&hash=" + hash;
- var authSendLV = new LoadVars();
- var authRecvLV = new LoadVars();
- authSendLV.ip = client.ip;
- authSendLV.userId = client.userId;
- authSendLV.userType = client.userType;
- authSendLV.pasword = client.pasword;
- authSendLV.uniqId = client.uniqId;
- authSendLV.userName = client.userName;
- authSendLV.performerId = client.performerId;
- authSendLV.hash = application.hash;
- if(client.userType == "performer")
- {
- authSendLV.numberOfCameras = application.cameraNo;
- urlParams += "&numberOfCameras=" + application.cameraNo;
- }
- if(client.userType == "viewer")
- {
- authSendLV.sessionType = client.sessionType;
- authSendLV.md5 = client.md5Check;
- authSendLV.truePrivate = (client.truePrivate == null) ? false : client.truePrivate;
- urlParams += "&sessionType=" + client.sessionType + "&md5=" + client.md5Check + "&truePrivate=" + authSendLV.truePrivate;
- }
- trace(urlParams);
- if(client.userType == "viewer")
- authSendLV.sendAndLoad(application.baseUrl + application.authUrl, authRecvLV, "POST");
- else if(client.userType == "performer")
- authSendLV.sendAndLoad(application.baseUrl + application.authPerformerUrl, authRecvLV, "POST");
- authRecvLV.onLoad = function(success)
- {
- if (success)
- {
- if (this.status == "allow")
- {
- trace("Auth allowed " + this.status);
- application.initClientInterval(client);
- }
- else
- {
- trace("Auth denied " + this.status);
- }
- }
- else
- {
- trace("Call to auth unsuccess");
- }
- }
- }
- application.updateTopic = function(topic)
- {
- trace("updateTopic " + topic);
- application.topic = topic;
- var clients = application.clients;
- var n = clients.length;
- for(var i = 0; i < n; i++)
- {
- clients[i].call("updateTopic", null, topic);
- }
- }
- application.getTopic = function()
- {
- trace("getTopic " + application.topic + ", " + this);
- return application.topic;
- }
- application.askForNumberOfCameras = function()
- {
- trace("askForNumberOfCameras " + application.cameraNo);
- var clients = application.clients;
- var n = clients.length;
- for(var i = 0; i < n; i++)
- {
- if(clients[i].userType != "performer")
- clients[i].call("setCameraNo", null, application.cameraNo);
- }
- }
- application.ask_song = function()
- {
- trace("ask_song " + this.userId);
- var clients = application.clients;
- var n = clients.length;
- for(var i = 0; i < n; i++)
- {
- if(clients[i].userType == "performer")
- clients[i].call("ask_song", null, this.userId);
- }
- }
- application.send_song = function(song_path, position, id, title)
- {
- trace("send_song " + song_path + ", " + position + ", " + id + ", " + title);
- var clients = application.clients;
- var n = clients.length;
- for(var i = 0; i < n; i++)
- {
- if(clients[i].userId == id)
- clients[i].call("send_song", null, song_path, position, title);
- }
- }
- application.change_song = function(path, title)
- {
- trace("change_song " + path + ", " + title);
- var clients = application.clients;
- var n = clients.length;
- for(var i = 0; i < n; i++)
- {
- clients[i].call("play_song", null, path, title);
- }
- }
- application.initializeSpy = function()
- {
- trace("initializeSpy");
- }
- application.onPublish = function(clientObj, streamObj)
- {
- trace("onPublish " + clientObj + ", " + streamObj);
- }
- application.onUnpublish = function(clientObj, streamObj)
- {
- trace("onUnpublish " + clientObj + ", " + streamObj);
- }
- application.onStatus = function(info){
- trace("code: " + info.code + " level: " + info.level);
- trace(info.code + " details: " + info.details);
- };
- application.onStreamStatus = function(infoObject)
- {
- trace("onStreamStatus " + infoObject.code + ", " + infoObject.description + ", " + infoObject.details + ", " + infoObject.level);
- }
- application.rec = function(flvName, recStreamName, type)
- {
- trace("rec " + flvName + ", " + recStreamName + ", " + type);
- application.flvName = flvName;
- application.videoStream = Stream.get(flvName);
- if(application.videoStream)
- {
- application.videoStream.onStatus = application.onStreamStatus;
- trace("video stream recording");
- application.videoStream.record();
- application.videoStream.play(recStreamName);
- }
- }
- application.recStop = function(type)
- {
- trace("recstop " + type);
- if(application.videoStream)
- {
- trace("Stream length " + Stream.length(application.flvName));
- //application.videoStream.flush();
- application.videoStream.record(false);
- trace("Stream length " + Math.floor(Stream.length(application.flvName)));
- }
- var taxSendLV = new LoadVars();
- var taxRecvLV = new LoadVars();
- taxSendLV.performerId = application.performer.performerId;
- taxSendLV.userId = application.performer.userId;
- taxSendLV.userType = application.performer.userType;
- taxSendLV.uniqId = application.performer.uniqId;
- taxSendLV.pasword = application.performer.pasword;
- taxSendLV.lengt = Math.floor(Stream.length(application.flvName));
- taxSendLV.fmsId = application.fmsId;
- taxSendLV.flvName = application.flvName;
- taxSendLV.type = type;
- taxSendLV.hash = application.hash;
- taxSendLV.sendAndLoad(application.baseUrl + "fms/addvideo", taxRecvLV, "POST");
- taxRecvLV.onLoad = function(success)
- {
- if (success)
- {
- if (this.status == "allow")
- {
- trace("rec allowed " + this.status);
- }
- else
- {
- trace("rec denied " + this.status + ", " + this.log);
- }
- }
- else
- {
- trace("Call to rec unsuccess");
- }
- }
- }
- application.kick = function(id)
- {
- trace("kick " + id);
- var clients = application.clients;
- var n = clients.length;
- for(var i = 0; i < n; i++)
- {
- if(clients[i].userId == id)
- {
- clients[i].call("disconMes", null, "kick");
- application.disconnect(clients[i]);
- break;
- }
- }
- }
- application.kickSelf = function()
- {
- application.kick(this.userId);
- }
- application.ban = function(id)
- {
- trace("ban " + id);
- var clients = application.clients;
- var n = clients.length;
- for(var i = 0; i < n; i++)
- {
- if(clients[i].userId == id)
- {
- var banSendLV = new LoadVars();
- var banRecvLV = new LoadVars();
- banSendLV.ip = clients[i].ip;
- banSendLV.bannedUserId = id;
- banSendLV.userId = this.userId;
- banSendLV.pasword = this.pasword;
- banSendLV.performerId = clients[i].performerId;
- banSendLV.sendAndLoad(application.baseUrl + application.banUrl, banRecvLV, "POST");
- banRecvLV.onLoad = function(success)
- {
- if (success)
- {
- clients[i].call("disconMes", null, "ban");
- application.disconnect(clients[i]);
- trace("user banned successfully");
- }
- else
- {
- trace("Error banning user");
- }
- }
- break;
- }
- }
- }
- application.banSelf = function()
- {
- application.ban(this.userId);
- }
- application.privateInvitation = function(userName, userId, chips)
- {
- trace("privateInvitation " + userName + ", " + userId + ", " + chips);
- var clients = application.clients;
- var n = clients.length;
- for(var i = 0; i < n; i++)
- {
- if(clients[i].userId == userId)
- {
- var validateChipsSendLV = new LoadVars();
- var validateChipsRecvLV = new LoadVars();
- validateChipsSendLV.ip = clients[i].ip;
- validateChipsSendLV.userId = userId;
- validateChipsSendLV.userName = userName;
- validateChipsSendLV.userType = clients[i].userType;
- validateChipsSendLV.pasword = clients[i].pasword;
- validateChipsSendLV.performerId = clients[i].performerId;
- validateChipsSendLV.uniqId = clients[i].uniqId;
- validateChipsSendLV.hash = application.hash;
- validateChipsSendLV.sendAndLoad(application.baseUrl + application.validateChipsUrl, validateChipsRecvLV, "POST");
- validateChipsRecvLV.onLoad = function(success)
- {
- if(success)
- {
- if(this.status == "allow")
- application.performer.call("privateInvitation", null, userName, userId, chips);
- trace("validate chips " + this.status + ", log" + this.log);
- }
- else
- {
- trace("validate chips unsuccessful");
- }
- }
- }
- if(clients[i].userType == "performer")
- {
- clients[i].call("privateInvitation", null, userName, userId, chips);
- }
- }
- }
- application.acceptInvitation = function(id)
- {
- trace("acceptInvitation " + id);
- var clients = application.clients;
- var n = clients.length;
- for(var i = 0; i < n; i++)
- {
- if(clients[i].userId == id)
- {
- clients[i].call("acceptInvitation", null);
- }
- }
- }
- application.rejectInvitation = function(id)
- {
- trace("rejectInvitation " + id);
- var clients = application.clients;
- var n = clients.length;
- for(var i = 0; i < n; i++)
- {
- if(clients[i].userId == id)
- {
- clients[i].call("rejectInvitation", null);
- break;
- }
- }
- }
- application.enterPrivate = function()
- {
- trace("enterPrivate");
- var clients = application.clients;
- var n = clients.length;
- for(var i = 0; i < n; i++)
- {
- /*if(clients[i].userType == "performer")
- clients[i].call("changeStatus", null, "private");*/
- }
- }
- application.changeSessionTypeToPrivate = function(isRealPrivate)
- {
- var privateSendLV = new LoadVars();
- var privateRecvLV = new LoadVars();
- privateSendLV.userId = this.userId;
- privateSendLV.uniqId = this.uniqId;
- privateSendLV.performerId = this.performerId;
- privateSendLV.isTruePrivate = isRealPrivate;
- privateSendLV.hash = application.hash;
- privateSendLV.sendAndLoad(application.baseUrl + application.truePrivateUrl, privateRecvLV, "POST");
- privateRecvLV.onLoad = function(success)
- {
- if (success)
- {
- trace("trueprivate called successfully");
- }
- else
- {
- trace("Call to trueprivate unsuccess");
- }
- }
- trace("changeSessionTypeToPrivate " + isRealPrivate);
- this.truePrivate = isRealPrivate;
- this.sessionType = (isRealPrivate == "true") ? "true_private" : "private";
- application.performer.call("changeStatus", null, "private");
- var clients = application.clients;
- var n = clients.length;
- for(var i = 0; i < n; i++)
- {
- if(clients[i] == this)
- {
- clients[i].call("changeStatus", null, "private");
- }
- else if(clients[i].userType != "performer")
- {
- //if(isRealPrivate == "true")
- clients[i].call("disconMes", null, "private");
- /*else
- clients[i].call("disconMes", null, "private_public");*/
- application.disconnect(clients[i]);
- }
- }
- }
- application.setViewerBroadcast = function(status)
- {
- trace("setViewerBroadcast " + status);
- var clients = application.clients;
- var n = clients.length;
- for(var i = 0; i < n; i++)
- {
- if(clients[i].userType == "performer")
- {
- clients[i].call("setViewerBroadcast", null, status, this.userId);
- }
- }
- }
- application.chatLogs = "";
- application.broadcastChatLine = function(userName, message, userId, nickColor)
- {
- trace("broadcastChatLine " + userName + ", " + message + ", " + userId, ", " + nickColor);
- var clients = application.clients;
- var n = clients.length;
- for(var i = 0; i < n; i++)
- {
- clients[i].call("getMsg", null, userName, message, userId, nickColor);
- }
- application.chatLogs += message + " ";
- }
- application.broadcastChatLineIcon = function(userName, message, userId, nickColor)
- {
- trace("broadcastChatLineIcon " + userName + ", " + message + ", " + userId, ", " + nickColor);
- var clients = application.clients;
- var n = clients.length;
- for(var i = 0; i < n; i++)
- {
- clients[i].call("getMsg", null, userName, message, userId, nickColor);
- }
- application.chatLogs += message + " ";
- }
- application.getFmsVersion = function()
- {
- return FMS_VERSION;
- }
- application.onDisconnect = function(client)
- {
- if(!client)
- return;
- trace("onDisconnect " + client.userName);
- if(client.userType == "performer")
- {
- var clients = application.clients;
- var n = clients.length;
- for(var i = 0; i < n; i++)
- {
- if(clients[i] != client)
- {
- clients[i].call("disconMes", null, "left");
- application.disconnect(clients[i]);
- }
- }
- }
- if(client != application.performer && client.sessionType == "private" || client.sessionType == "true_private")
- application.performer.call("changeStatus", null, "available");
- if(client != application.performer && client.sessionType == "true_private")
- application.performer.call("dressTime", null);
- if(client.userType == "performer" || client.userType == "viewer")
- {
- var endSessionSendLV = new LoadVars();
- var endSessionRecvLV = new LoadVars();
- endSessionSendLV.userId = client.userId;
- endSessionSendLV.userType = client.userType;
- endSessionSendLV.userName = client.userName;
- endSessionSendLV.uniqId = client.uniqId;
- endSessionSendLV.performerId = client.performerId;
- endSessionSendLV.ip = client.ip;
- endSessionSendLV.hash = application.hash;
- endSessionSendLV.pasword = client.pasword;
- endSessionSendLV.sendAndLoad(application.baseUrl + application.endSessionUrl, endSessionRecvLV, "POST");
- endSessionRecvLV.onLoad = function(success)
- {
- if (success)
- {
- trace("endsession called successfully " + this.status);
- }
- else
- {
- trace("Call to endsession unsuccess");
- }
- }
- }
- if(client.userType == "performer")
- {
- var chatLogSendLV = new LoadVars();
- var chatLogRecvLV = new LoadVars();
- chatLogSendLV.performerId = application.performer.userId;
- chatLogSendLV.pasword = application.performer.pasword;
- chatLogSendLV.mess = application.chatLogs;
- chatLogSendLV.hash = application.hash;
- trace("chatLogs " + application.chatLogs);
- chatLogSendLV.sendAndLoad(application.baseUrl + application.chatLogUrl, chatLogRecvLV, "POST");
- chatLogRecvLV.onLoad = function(success)
- {
- if (success)
- {
- trace("chat log called successfully " + this.status + ", log " + application.baseUrl + application.chatLogUrl);
- }
- else
- {
- trace("Call to chat log unsuccess");
- }
- }
- application.chatLogs = "";
- }
- }
- application.tipPerfromer = function(tipValue)
- {
- trace("tipPerfromer: " + tipValue + ", " + this.userName + ", " + this.userId);
- var tipSendLV = new LoadVars();
- var tipRecvLV = new LoadVars();
- tipSendLV.userId = this.userId;
- tipSendLV.uniqId = this.uniqId;
- tipSendLV.performerId = this.performerId;
- tipSendLV.amount = tipValue;
- tipSendLV.hash = application.hash;
- tipSendLV.pasword = this.pasword;
- tipSendLV.sendAndLoad(application.baseUrl + application.tipUrl, tipRecvLV, "POST");
- tipRecvLV.onLoad = function(success)
- {
- if (success)
- {
- trace("tipPerfromer called successfully " + this.status);
- }
- else
- {
- trace("Call to tipPerfromer unsuccess");
- }
- }
- var clients = application.clients;
- var n = clients.length;
- for(var i = 0; i < n; i++)
- {
- if(clients[i].userType == "performer")
- {
- clients[i].call("receivedTip", null, this.userId, this.userName, tipValue);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement