Skip to content

Commit

Permalink
Merge pull request #2 from csfwff/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
gakkiyomi authored Oct 8, 2021
2 parents cba6f67 + da1f667 commit 10e31b4
Show file tree
Hide file tree
Showing 276 changed files with 105,519 additions and 123 deletions.
10 changes: 10 additions & 0 deletions src/main/java/org/b3log/symphony/model/Pointtransfer.java
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,16 @@ public final class Pointtransfer {
*/
public static final int TRANSFER_TYPE_C_BLMZ = 37;

/**
* Transfer type - Activity - ADR.
*/
public static final int TRANSFER_TYPE_C_ACTIVITY_ADR = 38;

/**
* Transfer type - Activity - Mofish.
*/
public static final int TRANSFER_TYPE_C_ACTIVITY_MOFISH = 39;

/**
* Transfer sum - 摆龙门阵.
*/
Expand Down
87 changes: 87 additions & 0 deletions src/main/java/org/b3log/symphony/processor/ActivityProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.b3log.latke.ioc.Singleton;
import org.b3log.latke.model.User;
import org.b3log.latke.service.LangPropsService;
import org.b3log.latke.service.ServiceException;
import org.b3log.symphony.model.Common;
import org.b3log.symphony.model.Pointtransfer;
import org.b3log.symphony.model.UserExt;
Expand Down Expand Up @@ -118,6 +119,18 @@ public class ActivityProcessor {
@Inject
private LangPropsService langPropsService;

/**
* Pointtransfer management service.
*/
@Inject
private PointtransferMgmtService pointtransferMgmtService;

/**
* User query service.
*/
@Inject
private UserQueryService userQueryService;

/**
* Record if eating snake game is started.
*/
Expand All @@ -128,6 +141,11 @@ public class ActivityProcessor {
*/
final static SimpleCurrentLimiter EATING_SNAKE_CURRENT_LIMITER = new SimpleCurrentLimiter(12 * 60 * 60, 5);

/**
* Record ADR submit times 48hrs/req.
*/
public static SimpleCurrentLimiter ADRLimiter = new SimpleCurrentLimiter((48 * 60 * 60), 1);

/**
* Register request handlers.
*/
Expand All @@ -153,6 +171,75 @@ public static void register() {
Dispatcher.post("/activity/eating-snake/collect", activityProcessor::collectEatingSnake, loginCheck::handle, csrfMidware::fill);
Dispatcher.get("/activity/gobang", activityProcessor::showGobang, loginCheck::handle, csrfMidware::fill);
Dispatcher.post("/activity/gobang/start", activityProcessor::startGobang, loginCheck::handle);
Dispatcher.post("/api/games/adarkroom/share", activityProcessor::shareADarkRoomScore, loginCheck::handle, csrfMidware::check);
Dispatcher.post("/api/games/mofish/score", activityProcessor::shareMofishScore);
}

/**
* 上传摸鱼大闯关游戏成绩
*
* @param context
*/
public void shareMofishScore(final RequestContext context) {
try {
JSONObject requestJSONObject = context.requestJSON();
final String userName = requestJSONObject.optString("userName");
final int stage = requestJSONObject.optInt("stage");
final long time = requestJSONObject.optLong("time");
final JSONObject user = userQueryService.getUserByName(userName);
final boolean succ = null != pointtransferMgmtService.transfer(Pointtransfer.ID_C_SYS, user.optString(Keys.OBJECT_ID),
Pointtransfer.TRANSFER_TYPE_C_ACTIVITY_MOFISH, stage,
time + "", System.currentTimeMillis(), "");
if (!succ) {
throw new ServiceException(langPropsService.get("transferFailLabel"));
}
context.renderJSON(StatusCodes.SUCC);
context.renderMsg("数据上传成功!");
} catch (Exception e) {
context.renderJSON(StatusCodes.ERR);
context.renderMsg("存储数据失败!原因:未知原因");
}
}

/**
* 上传 ADarkRoom 游戏成绩
*
* @param context
*/
public void shareADarkRoomScore(final RequestContext context) {
try {
JSONObject requestJSONObject = context.requestJSON();
final int score = requestJSONObject.optInt("score");
try {
JSONObject currentUser = Sessions.getUser();
if (ADRLimiter.access(currentUser.optString(User.USER_NAME))) {
int amout = 10;
if (score > 1000) {
amout = score / 1000;
}
if (amout > 200) {
amout = 200;
}
final boolean succ = null != pointtransferMgmtService.transfer(Pointtransfer.ID_C_SYS, currentUser.optString(Keys.OBJECT_ID),
Pointtransfer.TRANSFER_TYPE_C_ACTIVITY_ADR, amout,
score + "", System.currentTimeMillis(), "");
if (!succ) {
throw new ServiceException(langPropsService.get("transferFailLabel"));
}
context.renderJSON(StatusCodes.SUCC);
context.renderMsg("数据上传成功,恭喜你通关了!你获得了奖励 " + amout + " 积分!你可以在摸鱼派-总榜-ADarkRoom总分榜单中查看你的成绩!");
} else {
context.renderJSON(StatusCodes.ERR);
context.renderMsg("存储数据失败!原因:每 48 小时只允许提交一次成绩!");
}
} catch (NullPointerException e) {
context.renderJSON(StatusCodes.ERR);
context.renderMsg("存储数据失败!原因:你还没有登录摸鱼派,请前往摸鱼派 https://pwl.icu 登录账号后重试。");
}
} catch (Exception e) {
context.renderJSON(StatusCodes.ERR);
context.renderMsg("存储数据失败!原因:请检查自己是否存在作弊行为!");
}
}

/**
Expand Down
92 changes: 92 additions & 0 deletions src/main/java/org/b3log/symphony/processor/CloudProcessor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Rhythm - A modern community (forum/BBS/SNS/blog) platform written in Java.
* Modified version from Symphony, Thanks Symphony :)
* Copyright (C) 2012-present, b3log.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.b3log.symphony.processor;

import org.b3log.latke.Keys;
import org.b3log.latke.http.Dispatcher;
import org.b3log.latke.http.RequestContext;
import org.b3log.latke.ioc.BeanManager;
import org.b3log.latke.ioc.Inject;
import org.b3log.latke.ioc.Singleton;
import org.b3log.latke.model.User;
import org.b3log.symphony.processor.middleware.CSRFMidware;
import org.b3log.symphony.processor.middleware.LoginCheckMidware;
import org.b3log.symphony.repository.CloudRepository;
import org.b3log.symphony.service.CloudService;
import org.b3log.symphony.util.Sessions;
import org.b3log.symphony.util.StatusCodes;
import org.json.JSONObject;

@Singleton
public class CloudProcessor {

@Inject
private CloudService cloudService;

@Inject
private CloudRepository cloudRepository;

/**
* Register request handlers.
*/
public static void register() {
final BeanManager beanManager = BeanManager.getInstance();
final LoginCheckMidware loginCheck = beanManager.getReference(LoginCheckMidware.class);
final CSRFMidware csrfMidware = beanManager.getReference(CSRFMidware.class);

final CloudProcessor cloudProcessor = beanManager.getReference(CloudProcessor.class);
Dispatcher.post("/api/cloud/sync", cloudProcessor::sync, loginCheck::handle, csrfMidware::check);
Dispatcher.post("/api/cloud/get", cloudProcessor::get, loginCheck::handle, csrfMidware::check);
}

/**
* 同步数据
*
* @param context
*/
public void sync(final RequestContext context) {
try {
JSONObject user = Sessions.getUser();
String userName = user.optString(User.USER_NAME);
String userId = user.optString(Keys.OBJECT_ID);

JSONObject requestJSONObject = context.requestJSON();
String gameId = requestJSONObject.optString("gameId");
String data = requestJSONObject.optString("data");
cloudService.sync(userId, gameId, data);
context.renderJSON(StatusCodes.SUCC).renderMsg("摸鱼派账号 " + userName + " - 游戏存档已同步至摸鱼派云服务");
} catch (Exception e) {
context.renderJSON(StatusCodes.ERR).renderMsg("将游戏存档同步至摸鱼派失败");
}
}

/**
* 获取存档
*
* @param context
*/
public void get(final RequestContext context) {
JSONObject user = Sessions.getUser();
String userId = user.optString(Keys.OBJECT_ID);
JSONObject requestJSONObject = context.requestJSON();
String gameId = requestJSONObject.optString("gameId");
String data = cloudService.getFromCloud(userId, gameId);
context.renderJSON(StatusCodes.SUCC).renderData(data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,14 @@ public static void register() {
Dispatcher.get("/hot", indexProcessor::showHotArticles, anonymousViewCheckMidware::handle);
Dispatcher.get("/perfect", indexProcessor::showPerfectArticles, anonymousViewCheckMidware::handle);
Dispatcher.get("/charge/point", indexProcessor::showChargePoint, anonymousViewCheckMidware::handle);
Dispatcher.get("/games/adarkroom/", indexProcessor::showADarkRoom, loginCheck::handle);
}

public void showADarkRoom(final RequestContext context) {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(context, "games/adarkroom/index.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
dataModelService.fillHeaderAndFooter(context, dataModel);
}

/**
* Show changelogs.
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/b3log/symphony/processor/Router.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ private static void registerProcessors() {
CaptchaProcessor.register();
// 聊天室
ChatroomProcessor.register();
// 云存储
CloudProcessor.register();
// 回帖
CommentProcessor.register();
// 文件上传
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/org/b3log/symphony/processor/TopProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ public static void register() {
Dispatcher.get("/top/consumption", topProcessor::showConsumption, anonymousViewCheckMidware::handle);
Dispatcher.get("/top/checkin", topProcessor::showCheckin, anonymousViewCheckMidware::handle);
Dispatcher.get("/top/online", topProcessor::showOnline, anonymousViewCheckMidware::handle);
Dispatcher.get("/top/adr", topProcessor::showADR, anonymousViewCheckMidware::handle);
Dispatcher.get("/top/mofish", topProcessor::showMofish, anonymousViewCheckMidware::handle);
}

/**
Expand Down Expand Up @@ -202,4 +204,40 @@ public void showOnline(final RequestContext context) {
dataModelService.fillSideTags(dataModel);
dataModelService.fillLatestCmts(dataModel);
}

/**
* Shows ADR score ranking list.
*
* @param context
*/
public void showADR(final RequestContext context) {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(context, "top/adr.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
final List<JSONObject> users = activityQueryService.getTopADR(Symphonys.TOP_CNT);
dataModel.put("topUsers", users);

dataModelService.fillHeaderAndFooter(context, dataModel);
dataModelService.fillRandomArticles(dataModel);
dataModelService.fillSideHotArticles(dataModel);
dataModelService.fillSideTags(dataModel);
dataModelService.fillLatestCmts(dataModel);
}

/**
* Shows Mofish score ranking list.
*
* @param context
*/
public void showMofish(final RequestContext context) {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(context, "top/mofish.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
final List<JSONObject> users = activityQueryService.getTopMofish(Symphonys.TOP_CNT);
dataModel.put("topUsers", users);

dataModelService.fillHeaderAndFooter(context, dataModel);
dataModelService.fillRandomArticles(dataModel);
dataModelService.fillSideHotArticles(dataModel);
dataModelService.fillSideTags(dataModel);
dataModelService.fillLatestCmts(dataModel);
}
}
25 changes: 25 additions & 0 deletions src/main/java/org/b3log/symphony/processor/UserProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ public void getUserInfo(final RequestContext context) {
filteredUserProfile.put(UserExt.USER_POINT, user.optInt(UserExt.USER_POINT));
filteredUserProfile.put(UserExt.USER_INTRO, user.optString(UserExt.USER_INTRO));
filteredUserProfile.put(Keys.OBJECT_ID, user.optString(Keys.OBJECT_ID));
filteredUserProfile.put(UserExt.USER_NO, user.optString(UserExt.USER_NO));
filteredUserProfile.put(UserExt.USER_APP_ROLE, user.optString(UserExt.USER_APP_ROLE));
final String userId = user.optString(Keys.OBJECT_ID);
final long followerCnt = followQueryService.getFollowerCount(userId, Follow.FOLLOWING_TYPE_C_USER);
filteredUserProfile.put("followerCount", followerCnt);
Expand All @@ -238,6 +240,29 @@ public void getUserInfo(final RequestContext context) {
filteredUserProfile.put("cardBg", cardBg);
}
}
// 检查用户是否关注过这个用户
try {
final JSONObject currentUser = Sessions.getUser();
if (currentUser == null) {
// 用户未登录
filteredUserProfile.put("canFollow", "hide");
} else {
final String currentUserId = currentUser.optString(Keys.OBJECT_ID);
if (currentUserId.equals(userId)) {
// 看的是自己
filteredUserProfile.put("canFollow", "hide");
} else {
final boolean isFollowing = followQueryService.isFollowing(currentUserId, userId, Follow.FOLLOWING_TYPE_C_USER);
if (isFollowing) {
filteredUserProfile.put("canFollow", "no");
} else {
filteredUserProfile.put("canFollow", "yes");
}
}
}
} catch (Exception e) {
filteredUserProfile.put("canFollow", "hide");
}

context.renderJSON(StatusCodes.SUCC).renderJSON(filteredUserProfile);
}
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/org/b3log/symphony/repository/CloudRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Rhythm - A modern community (forum/BBS/SNS/blog) platform written in Java.
* Modified version from Symphony, Thanks Symphony :)
* Copyright (C) 2012-present, b3log.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.b3log.symphony.repository;

import org.b3log.latke.repository.AbstractRepository;
import org.b3log.latke.repository.RepositoryException;
import org.b3log.latke.repository.annotation.Repository;
import org.json.JSONObject;

@Repository
public class CloudRepository extends AbstractRepository {

/**
* Public constructor.
*/
public CloudRepository() { super("cloud"); }

@Override
public String add(JSONObject jsonObject) throws RepositoryException {
return super.add(jsonObject);
}
}
Loading

0 comments on commit 10e31b4

Please sign in to comment.