Beispiel #1
0
	def post_command_core(key,cmd,cmd_count,user_count,client_id):
		#Heart beatだけの場合はcmd_count==0

		room=ChatRoom.get(key)#db.get(key)
		if(room==None):
			return Chat.ERROR_NO_ROOM
		if(not(client_id in room.channel_client_list)):
			return Chat.ERROR_DISCONNECT

		if(user_count!=-1):
			room.user_count=user_count
		if(room.command_list==""):
			room.command_list=cmd
		else:
			if(cmd!=""):
				room.command_list=room.command_list+" , "+cmd
		room.command_cnt=room.command_cnt+cmd_count
		room.heart_beat[client_id]=Chat.get_sec(datetime.datetime.now())
		auto_logout=Chat.auto_logout(room)

		#room_size=len(db.model_to_protobuf(room).Encode())
		room_size=sys.getsizeof(room.command_list)

		room.put()

		for client in room.channel_client_list:
			if(cmd_count!=0):
				channel.send_message( client , "update" )
			if(auto_logout):
				channel.send_message( client , "update_user" )

		return room_size
Beispiel #2
0
	def post_snapshot_core(key,snap_shot_0,snap_shot_1,snap_range,thumbnail):
		#スナップショットを格納
		room=ChatRoom.get(key)#db.get(key)
		
		#既にスナップショットが作成されている
		if(room.snap_range>=snap_range):
			return

		#サムネイルを格納
		room.thumbnail=db.Blob(base64.b64decode(thumbnail))

		#スナップショットまでのコマンドを消去
		server_command_list=room.command_list.split(" , ")
		new_command_list=""
		limit=room.command_cnt
		for i in range(snap_range,limit):
			cmd=server_command_list[i-room.snap_range]
			if(new_command_list==""):
				new_command_list=cmd
			else:
				new_command_list=new_command_list+" , "+cmd
		
		#スナップショットコマンドを追加
		room.command_list=new_command_list

		#スナップショットを格納
		room.snap_range=snap_range
		room.snap_shot_0=snap_shot_0
		room.snap_shot_1=snap_shot_1

		room.put()
Beispiel #3
0
	def get_snap_shot(self):
		try:
			room=ChatRoom.get(self.request.get("key"))#db.get(str(self.request.get("key")))
		except:
			ApiObject.write_json_core(self,{"status":"failed"})
			return

		if(room==None):
			ApiObject.write_json_core(self,{"status":"not_found"})
			return
			
		ApiObject.write_json_core(self,{"status":"success","snap_shot_0":room.snap_shot_0,"snap_shot_1":room.snap_shot_1,"snap_range":room.snap_range})
Beispiel #4
0
	def close_room(self,user):
		try:
			room=ChatRoom.get(self.request.get("key"))#db.get(self.request.get("key"))
		except:
			room=None
		if(not room):
			Alert.alert_msg_with_write(self,"ルームが見つかりません。")
			return
		if(not user or room.user_id!=user.user_id()):
			Alert.alert_msg_with_write(self,"終了する権限がありません。")
			return
		room.delete()
		self.redirect("./chat")
Beispiel #5
0
	def remove_user_core(room_key,client_id):
		room=ChatRoom.get(room_key)#db.get(room_key)

		#対象者を削除
		if(room.channel_client_list.count(client_id)):
			room.channel_client_list.remove(client_id)

		#自動ログアウト
		auto_logout=Chat.auto_logout(room)

		#ユーザ数を変更
		room.user_count=len(room.channel_client_list)

		room.put()
Beispiel #6
0
	def add_user_core(room_key,client_id):
		room=ChatRoom.get(room_key)#db.get(room_key)

		#ユーザの追加
		if(not room.channel_client_list):
			room.channel_client_list=[]	#ログイン中
		if(not room.channel_client_list_for_reconnect):
			room.channel_client_list_for_reconnect=[]	#再接続
		if(not room.heart_beat):
			room.heart_beat={}

		room.channel_client_list.append(client_id)
		room.channel_client_list_for_reconnect.append(client_id)

		room.heart_beat[client_id]=Chat.get_sec(datetime.datetime.now())

		#ユーザ数を変更
		room.user_count=len(room.channel_client_list)
		room.put()
Beispiel #7
0
	def get_command(self):
		try:
			room=ChatRoom.get(self.request.get("key"))#db.get(str(self.request.get("key")))
		except:
			ApiObject.write_json_core(self,{"status":"failed"})
			return

		if(room==None):
			ApiObject.write_json_core(self,{"status":"not_found"})
			return

		client_id=self.request.get("client_id")
		if(not(client_id in room.channel_client_list)):
			ApiObject.write_json_core(self,{"status":"disconnect"})
			return

		try:
			offset=int(self.request.get("offset"))
		except:
			ApiObject.write_json_core(self,{"status":"offset_overflow"})
			return

		limit=int(self.request.get("limit"))
		
		now_len=room.command_cnt
		if (offset+limit)>now_len:
			limit=now_len-offset
		
		server_command_list=room.command_list.split(" , ")
		
		command_list=[]
		for i in range(offset,offset+limit):
			if(i<room.snap_range):
				cmd_nop=4
				nop_command="[{'cmd':"+str(cmd_nop)+"}]";
				command_list.append(nop_command)
			else:
				one_cmd=server_command_list[i-room.snap_range]
				command_list.append(one_cmd)
		
		ApiObject.write_json_core(self,{"status":"success","offset":offset,"count":limit,"command_list":command_list})
Beispiel #8
0
	def get_user_list(self):
		try:
			room=ChatRoom.get(self.request.get("key"))#db.get(str(self.request.get("key")))
		except:
			ApiObject.write_json_core(self,{"status":"failed"})
			return

		if(room==None):
			ApiObject.write_json_core(self,{"status":"not_found"})
			return

		dic={}
		for client in room.channel_client_list:
			user_id=client.split("_")[0]
			name="unknown"
			bookmark=ApiObject.get_bookmark_of_user_id(user_id)
			if(bookmark):
				name=bookmark.name
			name=str(client.split("_")[2]).replace("-","%")
			name=urllib.unquote_plus(name)
			dic[client]=name
		
		ApiObject.write_json_core(self,{"status":"success","user_list":dic});
Beispiel #9
0
	def tool(self,user):
		bbs=None
		bbs_key=""
		thread_key=""

		if(self.request.get("key")=="always"):
			try:
				room_key=ChatRoom.all().filter("is_always =",1).fetch(1)[0].key()
			except:
				room_key=None
		else:
			room_key=self.request.get("key")
		if(not room_key):
			Alert.alert_msg_with_write(self,"ルームキーが必要です。")
			return

		ipad=CssDesign.is_tablet(self)
		viewmode=self.request.get("viewmode")
		password=self.request.get("pass")

		try:
			room=ChatRoom.get(room_key)#db.get(room_key)
		except:
			room=None

		alert_footer=""#<BR><A HREF='./chat'><IMG SRC='./static_files/chat/logo.png'/></A>"

		login_message=""
		if(not user):
			login_url=users.create_login_url(self.request.url)
			login_message="<BR><A HREF='"+login_url+"' class='g-button'>Googleアカウントでログイン</A><BR>"

		if(not room):
			Alert.alert_msg_with_write(self,"このチャットルームは終了されています。"+alert_footer)
			return
		
		if(room.password and room.password!=password):
			Alert.alert_msg_with_write(self,"チャットルームのパスワードが一致しません。"+alert_footer)
			return
		
		#if(not user):
		#	Alert.alert_msg_with_write(self,"チャットルームへの参加にはログインが必要です。<BR>"+login_message+alert_footer)
		#	return

		canvas_width=room.canvas_width
		canvas_height=room.canvas_height

		if(user):
			user_id=user.user_id()
			#user_name=self.get_user_name(user)
		else:
			user_id=0
		
		user_name=self.request.get("name")

		server_time=Chat.get_sec(datetime.datetime.now())
		
		if(user):
			bbs_list=Bbs.all().filter("user_id =",user.user_id()).filter("del_flag =",0).fetch(limit=10)
		else:
			bbs_list=None

		quote_name=urllib.quote_plus(str(user_name)).replace("%","-")
		client_id=str(user_id)+"_"+str(server_time)+"_"+quote_name
		token = channel.create_channel(client_id)

		#排他制御が必要
		Chat.add_user(room_key,client_id)

		template_values = {
		'host': "./",
		'bbs': bbs,
		'bbs_key': bbs_key,
		'thread_key': thread_key,
		'entry_key': "",
		'draw_time': "",
		'canvas_width': canvas_width,
		'canvas_height': canvas_height,
		'canvas_url': "",
		'reply': False,
		'summary': "",
		'author': "",
		'title': "",
		'chat': room_key,
		'ipad': ipad,
		'user_id':user_id,
		'user_name':user_name,
		'server_time':server_time,
		'bbs_list':bbs_list,
		'logined':True,
		'viewmode':viewmode,
		'room_name':room.name,
		'token':token,
		'client_id':client_id,
		'is_english':CssDesign.is_english(self)
		}
		
		path = '/html/tools/draw_window_ipad.htm'
		self.response.out.write(template_select.render(path, template_values))
Beispiel #10
0
	def remove_user(room_key,client_id):
		db.run_in_transaction(Chat.remove_user_core,room_key,client_id)
		room=ChatRoom.get(room_key)#db.get(room_key)
		Chat.user_update_notify(room)