跑马灯

back_recharge
zhangshanxue 2019-10-25 11:57:03 +08:00
parent 070774cc6b
commit 14e86450a4
9 changed files with 102 additions and 9 deletions

View File

@ -171,7 +171,7 @@ public class HandlerLogicThread extends Thread{
//内部codeErr统一处理
if(e instanceof ErrorCodeException){
int errCode = ErrorUtil.getExceptionErrorCodeValue(e);
LOGGER.error("\nuser:"+ session.getUid());
LOGGER.error("\nAn unusual ErrorCodeException occurred for the user::use"+ session.getUid());
if (errCode <= 0) {
//打印堆栈定位错误
LOGGER.error(ErrorUtil.getExceptionStackTraceFileLineAndMethod(e));

View File

@ -186,6 +186,7 @@ public class RedisKey {
public static final String MATCH_SERVER_INFO = "MATCH_SERVER_INFO";
public static final String LOGIC_SERVER_INFO = "LOGIC_SERVER_INFO";
public static final String BLOODY_SERVER_INFO = "BLOODY_SERVER_INFO";
public static final String SYSMSG = "SYSMSG";
public final static String CDKEY = "CDKEY";

View File

@ -713,12 +713,12 @@ public class RedisUtil {
}
//操作sortset score<<32+time
public void zsetAddOneOffsetByTime(String key, String uid, int score){
public void zsetAddOneOffsetByTime(String key, String value, int score){
for (int i = 0; i < MAX_TRY_TIMES; i++) {
try {
long s= (long)score<<40;
long sort = s+(0xFFFFFFFFFFL-(int)(System.currentTimeMillis()/1000));
redisTemplate.opsForZSet().add(key, uid, sort);
redisTemplate.opsForZSet().add(key, value, sort);
return;
} catch (Exception e) {
TimeUtils.sleep(FAILED_SLEEP);
@ -795,6 +795,18 @@ public class RedisUtil {
return null;
}
public Set<ZSetOperations.TypedTuple<String>> getZsetRangeWithScores(String type,String key, long start, long end){
String rkey = getKey(type, key);
for (int i = 0; i < MAX_TRY_TIMES; i++) {
try {
return redisTemplate.opsForZSet().rangeWithScores(rkey, start, end);
} catch (Exception e) {
TimeUtils.sleep(FAILED_SLEEP);
}
}
return null;
}
public Long getZSetreverseRank(String type,String key, String value){
String rkey = getKey(type,key);

View File

@ -56,7 +56,7 @@ public class ErrorCodeException extends Exception {
}
public String toString() {
return "[CODE: " + this.errorCode.code() + "][" + this.errorCode.message() + "] " + super.getMessage();
return "[CODE: " + this.errorCode.code() + "][" + this.errorCode.message() + "][" +((super.getMessage()==null)?"":super.getMessage())+ "][" +((params!=null&&params.size()!=0)?params.toString():"")+"] ";
}
public List<String> getParams() {

View File

@ -57,7 +57,7 @@ public interface Global {
int RENAME_SIZE_ERROR = 10003;
int SHOW_TIPS_ERROR = 20000;
//跑马灯状态
//跑马灯状态 需要配表
int LUCKY_LUCK = 1; //吉运
int DILIGENT = 2; //勤勉
int LUCKCAT = 3; //招财猫

View File

@ -1,20 +1,66 @@
package com.ljsd.jieling.kefu;
import com.google.gson.Gson;
import com.ljsd.GameApplication;
import com.ljsd.jieling.chat.logic.ChatLogic;
import com.ljsd.jieling.chat.messge.MessageCache;
import com.ljsd.jieling.db.redis.RedisKey;
import com.ljsd.jieling.db.redis.RedisUtil;
import com.ljsd.jieling.globals.Global;
import com.ljsd.jieling.network.server.ProtocolsManager;
import com.ljsd.jieling.protocols.ChatProto;
import com.ljsd.jieling.util.CBean2Proto;
import config.SSpecialConfig;
public class Cmd_sendmsg extends GmAbstract {
@Override
public boolean exec(String[] args) throws Exception {
if (args.length != 1) {
if (args.length < 3) {
return false;
}
String content = args[0];
ChatLogic.getInstance().sendSysChatMessage(content, Global.GMMSG, 0, 0, 0, 0, 0, 0);
int speed = Integer.valueOf(args[0]);
int multime = Integer.valueOf(args[1]);
double sendTime = args.length <= 3 ? 0 : Float.valueOf(args[2]);
StringBuilder stringBuilder = new StringBuilder();
for (int i = 3; i < args.length; i++) {
if (i != 3) {
stringBuilder.append(" ");
}
stringBuilder.append(args[i]);
}
String content = stringBuilder.toString();
Gson gson = new Gson();
ChatProto.ChatInfo.Builder chatInfo = ChatProto.ChatInfo.newBuilder();
chatInfo.setItemId(0);
chatInfo.setMessageId(0);
chatInfo.setTimes(System.currentTimeMillis());
chatInfo.setMsg(content);
chatInfo.setType(0);
chatInfo.setMessageType(Global.GMMSG);
if (speed <= 0) {
chatInfo.setSpeed(SSpecialConfig.getIntegerValue(SSpecialConfig.LAMP_TEXT_SPEED));
} else {
chatInfo.setSpeed(speed);
}
if (multime <= 0) {
chatInfo.setMultiple(1);
} else {
chatInfo.setMultiple(multime);
}
if (sendTime != 0f) {
String key = RedisKey.getKey(RedisKey.SYSMSG, "", false);
RedisUtil.getInstence().zsetAddOne(key, gson.toJson(chatInfo), sendTime);
} else {
long messageId = RedisUtil.getInstence().increment(GameApplication.serverId + RedisKey.CHAT_SYS_MSG_ID + GameApplication.serverId);
chatInfo.setMessageId(messageId);
MessageCache.addSystemMsg(chatInfo.build(), messageId);
}
return true;
}
}

View File

@ -127,7 +127,7 @@ public class PlayerManager extends MongoBase {
}
public void setNickName(String nickName) throws Exception {
// updateString("nickName", nickName);
updateString("nickName", nickName);
this.nickName = nickName;
}

View File

@ -25,6 +25,7 @@ import com.ljsd.jieling.logic.question.QuestionLogic;
import com.ljsd.jieling.logic.store.BuyGoodsLogic;
import com.ljsd.jieling.logic.store.StoreLogic;
import com.ljsd.jieling.network.server.ProtocolsManager;
import com.ljsd.jieling.util.MessageUtil;
import manager.STableManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -47,6 +48,7 @@ public class MinuteTask extends Thread {
LOGGER.info("online use num::"+ OnlineUserManager.sessionMap.entrySet().size());
HotfixUtil.getInstance().doWork("../conf/hotfix.json");
ActivityLogic.getInstance().checkActiviyStatus();
MessageUtil.checkAndSendMsg();
STableManager.updateTablesWithTableNames(true);
ActivityLogic.getInstance().checkSecretBoxSeason();
StoreLogic.checkGlobalStore(false);

View File

@ -1,9 +1,14 @@
package com.ljsd.jieling.util;
import com.google.gson.Gson;
import com.google.protobuf.GeneratedMessage;
import com.ljsd.GameApplication;
import com.ljsd.jieling.chat.messge.MessageCache;
import com.ljsd.jieling.core.GlobalsDef;
import com.ljsd.jieling.core.HandlerLogicThread;
import com.ljsd.jieling.core.SimpleTransaction;
import com.ljsd.jieling.db.redis.RedisKey;
import com.ljsd.jieling.db.redis.RedisUtil;
import com.ljsd.jieling.exception.ErrorCodeException;
import com.ljsd.jieling.exception.ErrorUtil;
import com.ljsd.jieling.globals.Global;
@ -17,6 +22,7 @@ import com.ljsd.jieling.protocols.*;
import config.SErrorCodeEerverConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.core.ZSetOperations;
import java.util.ArrayList;
import java.util.Arrays;
@ -347,4 +353,30 @@ public class MessageUtil {
*/
List<T> combine(List<T> list);
}
public static void checkAndSendMsg(){
Set<ZSetOperations.TypedTuple<String>> adventureBossRankInfo= RedisUtil.getInstence().getZsetreverseRangeWithScores(RedisKey.SYSMSG,"", 0,-1);
int rank = 0;
long current = System.currentTimeMillis();
for(ZSetOperations.TypedTuple<String> item : adventureBossRankInfo){
if(item.getScore()<=current){
try {
long messageId = RedisUtil.getInstence().increment(GameApplication.serverId + RedisKey.CHAT_SYS_MSG_ID+ GameApplication.serverId);
ChatProto.ChatInfo.Builder builder= new Gson().fromJson(item.getValue(),ChatProto.ChatInfo.Builder.class);
builder.setMessageId(messageId);
MessageCache.addSystemMsg(builder.build(),messageId);
}catch (Exception e){
LOGGER.error(e+"");
return;
}
rank++;
}else {
return;
}
}
if(rank>0){
String key = RedisKey.getKey(RedisKey.SYSMSG, "", false);
RedisUtil.getInstence().removeZSetRangeByRank(key, 0, rank);
}
}
}