Ejemplo n.º 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)
Ejemplo n.º 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="没有消息记录")
Ejemplo n.º 3
0
 def post(self, request, *args, **kwargs):
     username = request.POST['username']
     password = request.POST['password']
     try:
         User.objects.create_user(username=username, password=password)
     except Exception as e:
         return JsonResponse(state=2, msg='注册失败')
     return JsonResponse(state=0)
Ejemplo n.º 4
0
 def post(self, request, *args, **kwargs):
     room = Room.objects.get(id=kwargs['room_id'])
     if room.gm != request.user:
         return JsonResponse(state=2, msg='没有房主权限')
     task_id = request.POST.get('task_id')
     task = Task.objects.get(id=task_id)
     room.tasks.add(task)
     return JsonResponse(state=0)
Ejemplo n.º 5
0
 def post(self, request, *args, **kwargs):
     group_id = kwargs['group_id']
     room = Room.objects.get(room__id=group_id)
     if room.gm != request.user:
         return JsonResponse(state=2, msg="权限不足")
     player = User.objects.get(id=kwargs['user_id'])
     GroupMember.objects.filter(Q(group__id=group_id)
                                & Q(user=player)).update(send_msg=True)
     return JsonResponse(state=0)
Ejemplo n.º 6
0
 def form_valid(self, form):
     with transaction.atomic():
         if form.data.get('password'):
             form.instance.password = form.data.get('password')
         form.instance.gm = self.request.user
         form.instance.sidelines = form.data.get('sidelines') == 'on'
         form.save()
         room = Room.objects.get(id=form.instance.id)
         game_players = Group.objects.create(room=room, type=0)
         GroupMember.objects.create(group=game_players, user=room.gm)
         if form.data.get('sidelines'):
             bystanders = Group()
             bystanders.room = room
             bystanders.type = 1
             if form.data.get('sidelines_sendmsg'):
                 bystanders.send_msg = False
             bystanders.save()
         if not form.data.get('password'):
             Group.objects.create(room=room, type=2)
         dir_path = "static/resource/txt/" + room.gm.username
         os.makedirs(dir_path, exist_ok=True)
         txt_path = os.path.join(dir_path, "[" + str(int(time.time())) + "]" + room.id.hex + ".txt")
         with open(txt_path, 'w'):
             pass
         GameTxt.objects.create(room_id=str(room.id), user=room.gm, file=txt_path)
         txt_board_storeroom[room.id] = GameTxtPhantom()
         return JsonResponse(0, data={'room_id': str(room.id)})
Ejemplo n.º 7
0
 def post(self, request, *args, **kwargs):
     room_id = kwargs['room_id']
     room = Room.objects.get(id=room_id)
     player_ids = request.POST.getlist('player_ids')
     if len(player_ids) > 1:
         return JsonResponse(state=2, msg="不能转交给多个玩家")
     player_id = player_ids[0]
     item_id = request.POST['item_id']
     if room.gm == request.user:
         owner_id = request.POST['owner_id']
         RoomItemRecord.objects.filter(player_id=owner_id, room_id=room_id, item_id=item_id).update(
             player_id=player_id)
     else:
         RoomItemRecord.objects.filter(player__group_character__user=request.user, room_id=room_id,
                                       item_id=item_id).update(player_id=player_id)
     return JsonResponse(state=0)
Ejemplo n.º 8
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="没有消息记录")
Ejemplo n.º 9
0
 def form_valid(self, form):
     with transaction.atomic():
         form.instance.creator = self.request.user
         form.instance.description = form.data.get('description')
         form.save()
         xml_file_check(form.instance.init_file.name)
         return JsonResponse(state=0)
Ejemplo n.º 10
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)
Ejemplo n.º 11
0
 def post(self, request, *args, **kwargs):
     room = Room.objects.get(id=kwargs['room_id'])
     if room.gm != request.user:
         return JsonResponse(state=2, msg="权限不足")
     operation = request.POST.get('operation')
     if operation == 1:
         Group.objects.filter(Q(user__id=request.POST.get('user_id')) & Q(room=room))
         pass
     pass
Ejemplo n.º 12
0
 def post(self, request, *args, **kwargs):
     room_id = kwargs['room_id']
     player_ids = request.POST.getlist('player_ids')
     skill_id = request.POST['skill_id']
     skill = Skill.objects.get(id=skill_id)
     if skill.unique:
         if len(player_ids) > 1:
             return JsonResponse(state=2, msg='独有技能不能赋予两个以上角色')
         try:
             RoomSkillRecord.objects.get(Q(room_id=room_id) & Q(skill_id=skill_id))
             return JsonResponse(state=2, msg='已存在该独有技能')
         except RoomSkillRecord.MultipleObjectsReturned:
             return JsonResponse(state=2, msg='多于两个独有技能')
         except RoomSkillRecord.DoesNotExist:
             pass
     skill_record_list = [RoomSkillRecord(player_id=player_id, room_id=room_id, skill=skill) for player_id in
                          player_ids]
     RoomSkillRecord.objects.bulk_create(skill_record_list)
     return JsonResponse(state=0)
Ejemplo n.º 13
0
 def post(self, request, *args, **kwargs):
     room_id = kwargs['room_id']
     player_ids = request.POST.getlist('player_ids')
     item_id = request.POST['item_id']
     item = Item.objects.get(id=item_id)
     if item.unique:
         if len(player_ids) > 1:
             return JsonResponse(state=2, msg='唯一物品不能赋予两个以上角色')
         try:
             RoomItemRecord.objects.get(Q(room_id=room_id) & Q(item_id=item_id))
             return JsonResponse(state=2, msg='已存在该唯一物品')
         except RoomItemRecord.MultipleObjectsReturned:
             return JsonResponse(state=2, msg='多于两个唯一物品')
         except RoomItemRecord.DoesNotExist:
             pass
     item_record_list = [RoomItemRecord(player_id=player_id, room_id=room_id, item_id=item_id) for player_id in
                         player_ids]
     RoomItemRecord.objects.bulk_create(item_record_list)
     return JsonResponse(state=0)
Ejemplo n.º 14
0
 def get(self, request, *args, **kwargs):
     task_record_id = kwargs['task_record_id']
     room = Room.objects.get(id=kwargs['room_id'])
     if room.gm != request.user:
         return JsonResponse(state=2, msg='不具有房主权限')
     task_record = TaskRecord.objects.select_related('room', 'task').get(id=task_record_id)
     with open(task_record.file.path, 'r', encoding='utf-8') as f:
         task_record_txt = f.readlines()
     return render(request, 'room/executing_task_detail.html',
                   context={'task_record': task_record, 'task_record_txt': task_record_txt})
Ejemplo n.º 15
0
 def form_valid(self, form):
     with transaction.atomic():
         if form.data.get('id'):
             form.instance.editor = self.request.user
         else:
             form.instance.creator = self.request.user
             form.instance.editor = self.request.user
         form.save()
         xml_file_check(form.instance.detail)
         return JsonResponse(state=0)
Ejemplo n.º 16
0
 def post(self, request, *args, **kwargs):
     group_id = kwargs['group_id']
     room = Group.objects.get(id=group_id).room
     if room.gm != request.user:
         return JsonResponse(state=2, msg='权限不足')
     player = User.objects.get(id=request.POST['user_id'])
     GroupMember.objects.exclude(
         group__type=int(request.POST['type'])).filter(
             user=player).delete()
     try:
         group = Group.objects.get(
             Q(room=room) & Q(type=int(request.POST['type'])))
     except Group.DoesNotExist:
         return JsonResponse(state=2, msg="不具有对应组")
     try:
         GroupMember.objects.create(group=group, user=player)
         return JsonResponse(state=0)
     except Exception:
         return JsonResponse(state=2, msg='玩家已在游戏组中')
Ejemplo n.º 17
0
 def post(self, request, *args, **kwargs):
     task_record_id = request.POST['task_record_id']
     task_record = TaskRecord.objects.get(id=task_record_id)
     task_record.update_time = datetime.now()
     task_record.save()
     record = request.POST.get('record')
     with open(task_record.file.path, 'a', encoding='utf-8') as f:
         f.write(str(datetime.now()) + ':' + '\n')
         f.write(record)
         f.write('\n')
     return JsonResponse(state=0)
Ejemplo n.º 18
0
 def post(self, request, *args, **kwargs):
     room_id = kwargs['room_id']
     room = Room.objects.get(id=room_id)
     skill_id = request.POST['skill_id']
     if room.gm == request.user:
         player_id = request.POST['player_id']
         RoomSkillRecord.objects.filter(player_id=player_id, room_id=room_id, skill_id=skill_id).delete()
     else:
         RoomSkillRecord.objects.filter(player__group_character__user=request.user, room_id=room_id,
                                        skill_id=skill_id).delete()
     return JsonResponse(state=0)
Ejemplo n.º 19
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)
Ejemplo n.º 20
0
 def get(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="不具有房主权限")
     self.queryset = Task.objects.filter(Q(room_task__id=room_id))
     self.object_list = self.get_queryset()
     context = self.get_context_data()
     task_before_list = TaskRecord.objects.filter(room_id=room_id)
     context['task_before_list'] = task_before_list
     task_after_list = Task.objects.filter(Q(creator=request.user) | Q(private=False))
     context['task_after_list'] = task_after_list
     context['is_gm'] = True
     context['room_id'] = kwargs['room_id']
     return self.render_to_response(context)
Ejemplo n.º 21
0
 def form_valid(self, form):
     room_id = form.data.get('room_id')
     form.instance.room = Room.objects.get(id=room_id)
     task_id = form.data.get('task_id')
     form.instance.task = Task.objects.get(id=task_id)
     start = form.data.get('start')
     dir_path = "static/resource/game/records/"
     os.makedirs(dir_path, exist_ok=True)
     txt_path = os.path.join(dir_path, "[" + str(int(time.time())) + "]" + form.instance.id + ".txt")
     with open(txt_path, 'w', encoding='utf-8') as f:
         f.write(str(datetime.now())+':'+'\n')
         f.write(str(datetime.now()))
         f.write('\n')
     form.instance.file = txt_path
     form.save()
     return JsonResponse(state=0)
Ejemplo n.º 22
0
 def get(self, request, *args, **kwargs):
     item_id = kwargs['item_id']
     item = Item.objects.get(id=item_id)
     item_info = {}
     if item.file:
         character_xml = ET.parse(item.file)
         r = character_xml.getroot()
         print(r.tag)
         if r.tag != 'item':
             return JsonResponse(state=2, msg='文件不符合模板错误')
         for i in r:
             text = i.text.replace(i.tail, '')
             text = text.replace('\t', '')
             item_info[i.tag] = text
     return render(request,
                   'game/item_detail.html',
                   context={
                       'item': item,
                       'item_info': item_info
                   })
Ejemplo n.º 23
0
 def get(self, request, *args, **kwargs):
     skill_id = kwargs['skill_id']
     skill = Skill.objects.get(id=skill_id)
     skill_info = {}
     if skill.file:
         character_xml = ET.parse(skill.file)
         r = character_xml.getroot()
         print(r.tag)
         if r.tag != 'skill':
             return JsonResponse(state=2, msg='文件不符合模板错误')
         for i in r:
             text = i.text.replace(i.tail, '')
             text = text.replace('\t', '')
             skill_info[i.tag] = text
     return render(request,
                   'game/skill_detail.html',
                   context={
                       'skill': skill,
                       'skill_info': skill_info
                   })
Ejemplo n.º 24
0
 def get(self, request, *args, **kwargs):
     character_id = kwargs['character_uuid']
     character = Character.objects.get(id=character_id)
     if character.sex == 0:
         sex = '男'
     elif character.sex == 1:
         sex = '女'
     else:
         sex = '其他'
     character_info = {'id': character.id.hex, 'name': character.name, 'sex': sex}
     character_xml = ET.parse(character.detail)
     r = character_xml.getroot()
     print(r.tag)
     if r.tag != 'character':
         return JsonResponse(state=2, msg='文件不符合模板错误')
     for i in r:
         text = i.text.replace(i.tail, '')
         text = text.replace('\t', '')
         character_info[i.tag] = text
     return render(request, 'character/character_detail.html',
                   context={'character': character, 'character_info': character_info})
Ejemplo n.º 25
0
 def post(self, request, *args, **kwargs):
     record = TaskRecord.objects.get(id=request.POST['record_id'])
     with open(record.file.path) as f:
         txt = f.readlines()
     return JsonResponse(state=0, data=txt)
Ejemplo n.º 26
0
 def form_invalid(self, form):
     return JsonResponse(state=2, msg='数据异常,请检查输入数据。')
Ejemplo n.º 27
0
 def post(self, request, *args, **kwargs):
     Skill.objects.filter(id=request.POST['character_id'], creator=request.user).delete()
     return JsonResponse(state=0)
Ejemplo n.º 28
0
 def post(self, request, *args, **kwargs):
     user = request.user
     group = Group.objects.get(id=request.POST.get('group_id'))
     character = Character.objects.get(id=request.POST.get('character_id'))
     GroupMember.objects.filter(group=group).filter(user=user).update(character=character)
     return JsonResponse(state=0)
Ejemplo n.º 29
0
 def post(self, request, *args, **kwargs):
     character = Character.objects.get(id=request.POST['character_id'])
     task = Task.objects.get(id=request.POST['task_id'])
     task.npc.add(character)
     return JsonResponse(state=0, msg='添加成功')
Ejemplo n.º 30
0
 def post(self, request, *args, **kwargs):
     room_id = kwargs['room_id']
     room = Room.objects.get(id=room_id)
     try:
         group = Group.objects.get(Q(users=request.user) & Q(room=room))
         if group.type == 2:
             return JsonResponse(state=2, msg="申请尚未通过")
         else:
             return JsonResponse(state=0, data={'group_id': str(group.id)})
     except Exception as e:
         pass
     if room.password:
         password = request.POST.get('password')
         if not password:
             return JsonResponse(state=2, msg="请输入密码")
         if password != room.password:
             return JsonResponse(state=2, msg="密码错误")
         if room.state == 1 and room.sidelines:
             group = Group.objects.get(Q(room=room) & Q(type=1))
             GroupMember.objects.create(user=request.user, group=group)
             return JsonResponse(state=0, data={'group_id': str(group.id)})
         elif room.state == 0:
             group = Group.objects.get(Q(room=room) & Q(type=0))
             GroupMember.objects.create(user=request.user, group=group)
             return JsonResponse(state=0, data={'group_id': str(group.id)})
         elif room.state == -1:
             return JsonResponse(state=2, msg="已结团")
         else:
             return JsonResponse(state=2, msg="加入房间失败")
     else:
         if room.sidelines:
             group = Group.objects.get(Q(room=room) & Q(type=2))
             GroupMember.objects.create(user=request.user, group=group)
             return JsonResponse(state=2, msg="已提交申请")
         elif room.state == 1 and not room.sidelines:
             return JsonResponse(state=2, msg="跑团中,禁止旁观")
         elif room.state == -1:
             return JsonResponse(state=2, msg="已结团")
         else:
             return JsonResponse(state=2, msg="加入房间失败")