예제 #1
0
 def post(self, request, *args, **kwargs):
     room_id = kwargs['room_id']
     room = Room.objects.get(id=room_id)
     if room.gm != request.user:
         return JsonResponse(state=2, msg="不具有房主权限")
     game_txt_phantom = txt_board_storeroom.get(room_id)
     if game_txt_phantom:
         game_txt_phantom.get_by_state('game').append(CharacterTxt(name='GM',
                                                                   content='\n-------------------------\n结团时间:' + str(
                                                                       datetime.now()) + '\n-------------------------\n',
                                                                   time=datetime.now()))
         Group.objects.filter(room=room).update(send_msg=False)
         txt_list = [str(txt) for txt in game_txt_phantom.get_by_state('game')]
         if txt_list:
             game_txt = GameTxt.objects.filter(user=request.user).get(room_id=room_id)
             with open(game_txt.file.path, 'a') as f:
                 for t in txt_list:
                     f.write(t)
                     f.write('\n')
     txt_board_storeroom['room_id'] = None
     record_dict = {}
     record_dict['游戏文本'] = str(GameTxt.objects.get(room_id=room_id).file)
     for task_record in TaskRecord.objects.select_related('task').filter(room_id=room_id):
         record_dict[task_record.task.name] = str(task_record.file)
     room.state = -1
     room.save()
     return JsonResponse(state=0, data=record_dict)
예제 #2
0
 def post(self, request, *args, **kwargs):
     user = request.user
     room_id = kwargs['room_id']
     room = Room.objects.get(id=room_id)
     if room.gm != user:
         return JsonResponse(state=2, msg='不具有权限')
     room.state = 0
     room.save()
     game_txt_phantom = txt_board_storeroom.get(room_id)
     if game_txt_phantom:
         game_txt_phantom.get_by_state('game').append(CharacterTxt(name='GM',
                                                                   content='\n-------------------------\n存盘时间:' + str(
                                                                       datetime.now()) + '\n-------------------------\n',
                                                                   time=datetime.now()))
         Group.objects.filter(Q(room=room) & Q(users=user)).update(send_msg=False)
         txt_list = [str(txt) for txt in game_txt_phantom.get_by_state('game')]
         if txt_list:
             game_txt = GameTxt.objects.filter(user=request.user).get(room_id=room_id)
             with open(game_txt.file.path, 'a') as f:
                 for t in txt_list:
                     f.write(t)
                     f.write('\n')
             game_txt_phantom.clear_by_state('game')
             Group.objects.filter(Q(room=room) & Q(users=user)).update(send_msg=False)
             return JsonResponse(state=0)
         else:
             return JsonResponse(state=2, msg="没有消息记录")
     else:
         return JsonResponse(state=2, msg="没有消息记录")
예제 #3
0
 def get(self, request, *args, **kwargs):
     room_id = kwargs['room_id']
     state = request.GET.get('state')
     time_line = request.GET.get('time_line')
     if time_line:
         time_line = datetime.strptime(time_line, '%Y-%m-%d %H:%M:%S.%f')
     game_txt_phantom = txt_board_storeroom.get(room_id)
     if game_txt_phantom:
         txt_list = [str(txt) for txt in game_txt_phantom.get_by_state(state) if
                     not time_line or txt.time > time_line]
         if txt_list:
             return JsonResponse(state=0, data={'time_line': str(datetime.now()), 'list': txt_list})
         else:
             return JsonResponse(state=3, msg="没有新的消息")
     else:
         return JsonResponse(state=3, msg="没有消息记录")
예제 #4
0
 def post(self, request, *args, **kwargs):
     room_id = kwargs['room_id']
     room = Room.objects.get(id=room_id)
     if room.gm != request.user:
         return JsonResponse(state=2, msg='不是房主权限')
     room.state = 1
     room.save()
     t = datetime.now()
     game_txt_phantom = txt_board_storeroom.get(room_id)
     if not game_txt_phantom:
         game_txt_phantom = GameTxtPhantom()
         txt_board_storeroom[room_id] = game_txt_phantom
     game_txt_phantom.get_by_state('game').append(CharacterTxt(name='GM',
                                                               content='\n-------------------------\n游戏开始:' + str(
                                                                   datetime.now()) + '\n-------------------------\n',
                                                               time=datetime.now()))
     Group.objects.filter(Q(room=room) & Q(users=request.user)).update(send_msg=True)
     return JsonResponse(state=0)
예제 #5
0
 def post(self, request, *args, **kwargs):
     user = request.user
     room_id = kwargs['room_id']
     try:
         room = Room.objects.get(id=room_id)
         group = Group.objects.filter(room=room).get(users=user)
     except (Group.DoesNotExist, Group.MultipleObjectsReturned, Room.DoesNotExist, Room.MultipleObjectsReturned):
         return JsonResponse(state=2, msg="群组或房间异常")
     if not group.send_msg:
         return JsonResponse(state=2, msg="群组禁言中")
     text = request.POST.get('text')
     state = request.POST.get('state')
     if not text:
         return JsonResponse(state=1, msg="空白信息")
     if state == 'game':
         try:
             group_member = GroupMember.objects.filter(group=group).get(user=user)
             if not group_member.send_msg:
                 return JsonResponse(state=2, msg="角色被禁言")
             character = group_member.character
             name = character.name
         except Exception as e:
             # print(e)
             # return JsonResponse(state=1, msg="游戏角色获取异常"))
             name = '神秘声音'
     else:
         name = user.username
     if text.startswith('.'):
         text = DiceFilter.handle(text)
     text = WordFilter.handle(text)
     t = datetime.now()
     game_txt_phantom = txt_board_storeroom.get(room_id)
     if not game_txt_phantom:
         game_txt_phantom = GameTxtPhantom()
         txt_board_storeroom[room_id] = game_txt_phantom
     game_txt_phantom.get_by_state(state).append(CharacterTxt(name=name, content=text, time=t))
     return JsonResponse(state=0)