Skip to content

Commit

Permalink
1. fixed the thread exit before host issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
hezhenwei committed Aug 10, 2021
1 parent 0487041 commit bae2f09
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/MykesTool/MTDChatEngineThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@ public ChatReply(Player player, String strAsk)

public MTDChatEngineThread()
{
Log.info("Start MTDChatEngine Thread");
m_nRunning = 1;
this.start();
Log.info("Init MTDChatEngine Thread");
}

// note this may be called in another thread.
Expand All @@ -135,7 +133,8 @@ public void AskAsync(Player player, String strAsk, int nHideReply)
if( m_nDebug == 1) {
Log.info("Insert chat:"+player.toString()+":"+strAsk);
}
// if it's stopped because of server stop, restart it.
// start it here. becuase if we don't know when to exit, we check if hosting to exit.
// but if it host later after program start, the thread exit before it hosts.
if(m_nRunning == 0)
{
m_nRunning =1;
Expand All @@ -147,14 +146,14 @@ public void AskAsync(Player player, String strAsk, int nHideReply)
public ChatReply GetNextReply()
{
ChatReply chat = null;
Log.info("trying to get reply:");
//Log.info("trying to get reply:");
synchronized (m_ListReply) {
// find the one that has not get replied.
for (ChatReply chatOne:m_ListReply) {
Log.info("itering reply:"+chatOne.strReply);
//Log.info("itering reply:"+chatOne.strReply);
if( "" != chatOne.strReply) {
chat = chatOne;
Log.info("find reply:"+chatOne.strReply);
//Log.info("find reply:"+chatOne.strReply);
m_ListReply.remove(chatOne);
break;
}
Expand Down Expand Up @@ -213,9 +212,9 @@ public void run() {
Log.info(m_strLogPrefix + " error getting message.");
}
chat.strReply = strFormattedContent;
Log.info("adding chat reply "+chat);
//Log.info("adding chat reply "+chat);
synchronized (m_ListReply) {
Log.info("adding chat reply2 "+chat);
//Log.info("adding chat reply2 "+chat);
m_ListReply.add(chat);
}
}
Expand Down

0 comments on commit bae2f09

Please sign in to comment.