122 lines
5.7 KiB
Java
122 lines
5.7 KiB
Java
package com.alterdekim.game.controller;
|
|
|
|
import com.alterdekim.game.controller.result.async.*;
|
|
import com.alterdekim.game.entity.User;
|
|
import com.alterdekim.game.security.AuthenticationUtil;
|
|
import com.alterdekim.game.service.*;
|
|
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
|
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.http.MediaType;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.Optional;
|
|
import java.util.UUID;
|
|
|
|
@Slf4j
|
|
@RestController
|
|
public class AsyncController {
|
|
|
|
@Autowired
|
|
private MiniquestService miniquestService;
|
|
|
|
@Autowired
|
|
private PhoneMessageService phoneMessageService;
|
|
|
|
@Autowired
|
|
private PostcardService postcardService;
|
|
|
|
@Autowired
|
|
private PreloaderService preloaderService;
|
|
|
|
@Autowired
|
|
private PromotionBannerService promotionBannerService;
|
|
|
|
@Autowired
|
|
private PromotionService promotionService;
|
|
|
|
@Autowired
|
|
private UserService userService;
|
|
|
|
@PostMapping("/async/Ping")
|
|
@ResponseBody
|
|
public ResponseEntity<String> ping() {
|
|
return ResponseEntity.ok("<response isPong=\"true\" />");
|
|
}
|
|
|
|
@PostMapping("/async/ServerAction")
|
|
@ResponseBody
|
|
public ResponseEntity<String> serverAction() {
|
|
try {
|
|
//User user = AuthenticationUtil.authProfile(userService).orElse(userService.findByUsername("jerk"));
|
|
|
|
User user = AuthenticationUtil.authProfile(userService).get();
|
|
|
|
XmlMapper xmlMapper = new XmlMapper();
|
|
xmlMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE);
|
|
xmlMapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
|
|
ServerActionResult serverActionResult = new ServerActionResult();
|
|
serverActionResult.setSn_status(new SnStatus(false));
|
|
serverActionResult.setUser_name(new UserName(user.getUsername()));
|
|
serverActionResult.setFlags(new Flags(true, 13));
|
|
serverActionResult.setRequests(new Grants(0));
|
|
serverActionResult.setGrants(new Grants(0));
|
|
List<ConfigItem> items = new ArrayList<>();
|
|
items.add(new ConfigItem(1, ServerActionConfigType.IsPreloaderEnabled, "1", "bool")); // play with it
|
|
items.add(new ConfigItem(2, ServerActionConfigType.SynchronizeAvatarRotation, "1", "bool"));
|
|
items.add(new ConfigItem(3, ServerActionConfigType.InitialVolumeValue, "30", "number"));
|
|
items.add(new ConfigItem(4, ServerActionConfigType.IsStartupHomeLocation, "0", "bool"));
|
|
items.add(new ConfigItem(5, ServerActionConfigType.AccessRoleFlags, "0", "number"));
|
|
items.add(new ConfigItem(6, ServerActionConfigType.IsInternational, "0", "bool")); // play with it
|
|
items.add(new ConfigItem(7, ServerActionConfigType.TypeWeapon, "1", "number"));
|
|
items.add(new ConfigItem(8, ServerActionConfigType.StatisticsSendInterval, "300", "number"));
|
|
items.add(new ConfigItem(9, ServerActionConfigType.SwfVersion, "", "string"));
|
|
items.add(new ConfigItem(10, ServerActionConfigType.LanguageId, "1", "number")); // play with it
|
|
items.add(new ConfigItem(11, ServerActionConfigType.SnId, "1", "number"));
|
|
items.add(new ConfigItem(12, ServerActionConfigType.AutoServerSelectionAllowed, "0", "bool"));
|
|
List<ServerItem> s_items = new ArrayList<>();
|
|
s_items.add(new ServerItem(1, 202, 5, "rtmp://localhost:8888/shararam", 0, 1, 5, 5.1));
|
|
|
|
serverActionResult.setPhone(new PhoneMessages(phoneMessageService.getAllPhoneMessages()));
|
|
serverActionResult.setMiniquest(miniquestService.getAllMiniquests());
|
|
serverActionResult.setPostcard(new PostcardMessages(postcardService.getAllPostcards()));
|
|
serverActionResult.setPreloader(preloaderService.getAllPreloaders());
|
|
serverActionResult.setPromotion(promotionService.getAllPromotions());
|
|
serverActionResult.setPromotion_banner(promotionBannerService.getAllPromotionBanners());
|
|
|
|
|
|
List<Tutorial> tutorials = new ArrayList<>();
|
|
tutorials.add(new Tutorial(-1, 1));
|
|
tutorials.add(new Tutorial(1, 1));
|
|
tutorials.add(new Tutorial(2, 1));
|
|
tutorials.add(new Tutorial(3, 1));
|
|
tutorials.add(new Tutorial(4, 1));
|
|
tutorials.add(new Tutorial(5, 1));
|
|
serverActionResult.setTutorial(tutorials);
|
|
|
|
List<ServerActionCData> cdatas = new ArrayList<>();
|
|
cdatas.add(new ServerActionConfig(items));
|
|
cdatas.add(new ServerActionSystem(1, "cache/resources.swf")); // swf/cache/rus/resources[19].swf
|
|
cdatas.add(new ServerActionUser(user.getId(), AuthenticationUtil.getToken(user), AuthenticationUtil.getToken(user), 2));
|
|
cdatas.add(new ServerActionServers(s_items));
|
|
serverActionResult.setCdata(cdatas);
|
|
return ResponseEntity.ok()
|
|
.contentType(MediaType.APPLICATION_XML)
|
|
.body(xmlMapper.writeValueAsString(serverActionResult));
|
|
} catch (JsonProcessingException e) {
|
|
log.error(e.getMessage(), e);
|
|
}
|
|
return ResponseEntity.noContent().build();
|
|
}
|
|
}
|